I am trying to find data in mongodb. i am having data like this
{"name":"xxxx","product":"laptop,phone,mobile"}
{"name":"yyyy","product":"phone,iphone,pendrive"}
i am trying to find "phone" is in product key so i have tried this command in terminal
db.collection.find({"product": /phone/});
it is working fine but it is not working in my application.so i have tried dynamically like that in my application.
var key=phone;
var name="/"+key+"/";
collection.find({"product":name}).toArray(function(err,result)
{
console.log(result.length);
});
but i am always getting 0 length only so how to use that dynamically?