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

Spread the love
Last modified: February 6, 2020

Comments

Write a Reply or Comment

Your email address will not be published.