The operation returns the following document: 

{ "_id" : 5, "type" : "food", "item" : "aaa", "ratings" : [ 5, 8, 9 ] } 

## Match an Array Element 

Equality matches can specify a single element in the array to match. These specifications match if the array contains at least one element with the specified value. 

The following example queries for all documents where ratings is an array that contains 5 as one of its elements: 

db.inventory.find( { ratings: 5 } ) 

The operation returns the following documents: 

{ "_id" : 5, "type" : "food", "item" : "aaa", "ratings" : [ 5, 8, 9 ] } { "_id" : 6, "type" : "food", "item" : "bbb", "ratings" : [ 5, 9 ] } { "_id" : 7, "type" : "food", "item" : "ccc", "ratings" : [ 9, 5, 8 ] } 

## Match a Specific Element of an Array 

Equality matches can specify equality matches for an element at a particular index or position of the array using the dot notation . 

In the following example, the query uses the dot notation to match all documents where the ratings array contains 5 as the first element: 

db.inventory.find( { 'ratings.0': 5 } ) 

The operation returns the following documents: 

{ "_id" : 5, "type" : "food", "item" : "aaa", "ratings" : [ 5, 8, 9 ] } { "_id" : 6, "type" : "food", "item" : "bbb", "ratings" : [ 5, 9 ] } 

## Specify Multiple Criteria for Array Elements 

Single Element Satisfies the Criteria Use $elemMatch operator to specify multiple criteria on the elements of an array such that at least one array element satisfies all the specified criteria. 

The following example queries for documents where the ratings array contains at least one element that is greater than ( $gt ) 5 and less than ( $lt ) 9 : 

db.inventory.find( { ratings: { $elemMatch: { $gt: 5, $lt: 9 } } } ) 

The operation returns the following documents, whose ratings array contains the element 8 which meets the crite- ria: 

{ "_id" : 5, "type" : "food", "item" : "aaa", "ratings" : [ 5, 8, 9 ] } { "_id" : 7, "type" : "food", "item" : "ccc", "ratings" : [ 9, 5, 8 ] } 

Combination of Elements Satisfies the Criteria The following example queries for documents where the ratings array contains elements that in some combination satisfy the query conditions; e.g., one element can satisfy the greater than 5 condition and another element can satisfy the less than 9 condition, or a single element can satisfy both: 

