im using nodejs and mongoose to build an api, im trying to do the search feature, but it deosnt seem to query anything, the code.
app.get('/search', function(req,res){
return Questions.find({text: "noodles"}, function(err,q){
return res.send(q);
});
});
its not giving me any results, i know thier should be at least 4 results from this query, thiers 4 documents in the questions database with the word "noodles", everything is working the the database connection and my node server
What your query is doing is finding documents where the text
property matches "noodles"
exactly. Assuming you're trying to query for documents where the text
property simply contains "noodles"
somewhere, you should use a regular expression instead:
app.get('/search', function(req,res){
var regex = new RegExp('noodles', 'i'); // 'i' makes it case insensitive
return Questions.find({text: regex}, function(err,q){
return res.send(q);
});
});