Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by JohnnyHK for Combine two OR-queries with AND in Mongoose

It's probably easiest to create your query object directly as:

  Test.find({      $and: [          { $or: [{a: 1}, {b: 1}] },          { $or: [{c: 1}, {d: 1}] }      ]  }, function (err, results) {      ...  }

But you can also use the Query#and helper that's available in recent 3.x Mongoose releases:

  Test.find()      .and([          { $or: [{a: 1}, {b: 1}] },          { $or: [{c: 1}, {d: 1}] }      ])      .exec(function (err, results) {          ...      });

Viewing all articles
Browse latest Browse all 2

Trending Articles



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