I am using the $or
operator in mongoose for searching through the name
and description
fields of the database. I want to check if the queryWord
string contains any part of the database field(s). This is the code I am using:
const query = {$or: [ { name: `/${body.queryWord}/i` }, { description: { $regex: `/${body.queryWord}/i` } }, ],};Food.find(query, (err, data) => { if (err) { res.status(500).send(err); } else { res.status(200).send(data); }});
But it returns, only, an empty array!
Any help is greatly appreciated!
Thank You!