Quantcast
Channel: $or Operator in Mongoose - Stack Overflow
Viewing all articles
Browse latest Browse all 2

$or Operator in Mongoose

$
0
0

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!


Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>