I am using a substring value of "data" to search fields in the database having a substring "data" in them. I currently have two fields of that type.
Running the code with hard-coding " /data/i " in the "title" field returns the result but when I insert the variable substring
to the query for "title" it returns an empty array.
WORKS
router.post('/search',function(req,res){
let substring = req.body.substring;
console.log(substring);
substring = ('/'+substring+'/i');
console.log(String(substring));
data.find({title:/data/i},function(err,found){ //works here
if(err) console.log(err);
console.log(found);
});
});
Does Not Work
router.post('/search',function(req,res){
let substring = req.body.substring;
console.log(substring);
substring = ('/'+substring+'/i');
console.log(String(substring));
data.find({title:substring},function(err,found){ // doesnt work here
if(err) console.log(err);
console.log(found);
});
});