Monday 10 April 2017

Find query with multiple $or statements

I am trying to write a find query for MongoDb. I am not receiving any results and it's not making any sense to me. It could be because I am querying against a string and a list of strings. I am not sure. I am passing in two arrays with component and product. Product in the Database is a string while Component is a list of strings.

testCollection.find(
          {
            and: [
              {
                $or: req.body.component.map(entry => ({Components: { $in: [entry]}}))}]},
              {
                $or: req.body.product.map(entry => {Product: entry})}).toArray((err, docs) => {
                  if (err) throw err;
                  res.send(docs);
                    db.close();
          });



via mkteagle

No comments:

Post a Comment