MongoDB : find value in Array with multiple criteria

You can use $elemMatch to check if an element in an array matches a specified match expression.

In this case, you can use it to get a document whose numbers array has an element that is between -10 and 10:

   db.foo.find( { numbers : { $elemMatch : { $gt : -10 , $lt : 10 } } } );

This will just return the _id : 2 document.

Leave a Comment