Mongoose query (find) to match id with values stored as comma separated string in MongoDB
Assuming that we have stored the values into db is like
[
{
"tags": "fun,game,reading,photography"
},
{
"tags": "politics,game,workout,photography"
},
{
"tags": "programming,photography,business"
}
]
Model: Customer
Customer.find({$where : 'this.categoryid.indexOf("' + categoryId + '") != -1'});
Originally posted Here