i am trying to do the equivaleny in mongodb to sql LIKE search, but i cant have the results that i expected, i am follow this mappig sql to monog, but the result json is always empty. if i use a literal string works , but when pass a variable nothing happens
app.get("/questions/search/:query", function(req,res){
var querySearch = req.params.query;
//res.send(querySearch)
Question.find({title: /querySearch/ },function(err,docs){
if(err) res.json(err)
res.json(docs)
});
})
That find command will search for documents where the title contains the string "querySearch". This doesn't seem to be what you want to do. When you want to use find with a regular expression created at runtime, pass a RegExp object.
But please note that searching with regular expressions is slow. When you don't need all the features of regular expressions and only search for whole words, a text index might be the better choice.