Retrieve only the queried element in an object array in MongoDB collection

MongoDB 2.2’s new $elemMatch projection operator provides another way to alter the returned document to contain only the first matched shapes element: db.test.find( {“shapes.color”: “red”}, {_id: 0, shapes: {$elemMatch: {color: “red”}}}); Returns: {“shapes” : [{“shape”: “circle”, “color”: “red”}]} In 2.2 you can also do this using the $ projection operator, where the $ in a … Read more