OPTIONS

$elemMatch (query)

$elemMatch

New in version 1.4.

The $elemMatch operator matches more than one component within an array element. For example,

db.collection.find( { array: { $elemMatch: { value1: 1, value2: { $gt: 1 } } } } );

returns all documents in collection where the array array satisfies all of the conditions in the $elemMatch expression.

That is, where the value of value1 is 1 and the value of value2 is greater than 1. Matching arrays must have at least one element that matches all specified criteria. Therefore, the following document would not match the above query:

{ array: [ { value1:1, value2:0 }, { value1:2, value2:2 } ] }

while the following document would match this query:

{ array: [ { value1:1, value2:0 }, { value1:1, value2:2 } ] }
←   $all $size  →
ON THIS PAGE