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

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 ] } 

The document with the "ratings" : [ 5, 9 ] matches the query since the element 9 is greater than 5 (the first condition) and the element 5 is less than 9 (the second condition). 

## Array of Embedded Documents 

Consider that the inventory collection includes the following documents: 

{ _id: 100, type: "food", item: "xyz", qty: 25, price: 2.5, ratings: [ 5, 8, 9 ], memos: [ { memo: "on time", by: "shipping" }, { memo: "approved", by: "billing" } ] } { _id: 101, type: "fruit", item: "jkl", qty: 10, price: 4.25, ratings: [ 5, 9 ], memos: [ { memo: "on time", by: "payment" }, { memo: "delayed", by: "shipping" } ] } 

Match a Field in the Embedded Document Using the Array Index If you know the array index of the embedded document, you can specify the document using the embedded document’s position using the dot notation . 

The following example selects all documents where the memos contains an array whose first element (i.e. index is 0 ) is a document that contains the field by whose value is ’shipping’ : 

db.inventory.find( { 'memos.0.by': 'shipping' } ) 

The operation returns the following document: 

{ _id: 100, type: "food", item: "xyz", qty: 25, price: 2.5, ratings: [ 5, 8, 9 ], memos: [ { memo: "on time", by: "shipping" }, { memo: "approved", by: "billing" } ] } 

