Definition
$queryNote
Deprecated since v3.2
Starting in v3.2, the
$queryoperator is deprecated in themongoshell. In themongoshell, use cursor methods instead.The
$queryoperator forces MongoDB to interpret an expression as a query.The following
mongooperations are equivalent, and return only those documents in the collection namedcollectionwhere theagefield equals25.db.collection.find( { $query: { age : 25 } } ) db.collection.find( { age : 25 } ) $queryis necessary to work with documents that contain a field namequerywhose value is an embedded document, such as the following document:{ _id: 1, age: 25, query: { a: 1 } } The following find operation that does not use the
$queryoperator will return no results:db.documents.find( { query: { a: 1 } } ) To obtain the document, you will need to use the following query:
db.documents.find( { "$query": { query: { a: 1 } } } ) Tip
For more information about queries in MongoDB see Query Documents,
db.collection.find(), and Getting Started with MongoDB.Note
Do not mix query forms. If you use the
$queryformat, do not append cursor methods to thefind(). To modify the query use the meta-query operators, such as$explain.Therefore, the following two operations are equivalent:
db.collection.find( { $query: { age : 25 }, $explain: true } ) db.collection.find( { age : 25 } ).explain()