- Reference >
- Operators >
- Query Modifiers >
- $query
$query¶
On this page
Definition¶
-
$query
¶ Deprecated since v3.2
Starting in v3.2, the
$query
operator is deprecated in themongo
shell. In themongo
shell, use cursor methods instead.The
$query
operator forces MongoDB to interpret an expression as a query.The following
mongo
operations are equivalent, and return only those documents in the collection namedcollection
where theage
field equals25
.$query
is necessary to work with documents that contain a field namequery
whose value is an embedded document, such as the following document:The following find operation that does not use the
$query
operator will return no results:To obtain the document, you will need to use the following query:
See also
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
$query
format, 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: