my code is
var search_element=Session.get("search_string");
var adc="/"+search_element+"*/";
console.log(adc);
return Polls_Coll.find({question:{$regex:adc}});
Why it is not working
if i give
Polls_Coll.find({question:{$regex:/Best*/}});
in conslow it's working and if i substitute the regex with the value(search_element) it is not working. I think it is replacing like this
Polls_Coll.find({question:{$regex:"/Best*/"}});(with quotes "/Best*/")
Is that the main problem? or Is there any silly mistake i did??
There are two types of syntax:
Polls_Coll.find({question:/Best*/});
and
Polls_Coll.find({question:{$regex:"Best*"}});
You've used elements in each so thats probably why its not working. There's a bit more details about this at the mongodb docs: http://docs.mongodb.org/manual/reference/operator/query/regex/
Both forms work fine in Meteor, so you shouldn't have a problem with them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With