Query Modifiers

In addition to the MongoDB Query Operators, there are a number of “meta” operators thatlet you modify the output or behavior of a query.

Note

  • Deprecated in the mongo Shell since v3.2
  • Starting in v3.2, the query “meta” operators are deprecated inthe mongo shell. In the mongo shell, usethe cursor methodsinstead.

The driver interfaces may provide cursor methods that wrap these options. When possible,use these methods; otherwise, you can add these options using either ofthe following syntax:

  1. db.collection.find( { <query> } )._addSpecial( <option> )
  2. db.collection.find( { $query: { <query> }, <option> } )

Operators

Modifiers

Note

  • Deprecated in the mongo Shell since v3.2
  • Starting in v3.2, the query “meta” operators are deprecated inthe mongo shell. In the mongo shell, usethe cursor methodsinstead.
NameDescription
$commentAdds a comment to the query to identify queries in the database profiler output.
$explainForces MongoDB to report on query execution plans. See explain().
$hintForces MongoDB to use a specific index. See hint()
$maxSpecifies an exclusive upper limit for the index to use in a query. See max().
$maxTimeMSSpecifies a cumulative time limit in milliseconds for processing operations on a cursor. See maxTimeMS().
$minSpecifies an inclusive lower limit for the index to use in a query. See min().
$orderbyReturns a cursor with documents sorted according to a sort specification. See sort().
$queryWraps a query document.
$returnKeyForces the cursor to only return fields included in the index.
$showDiskLocModifies the documents returned to include references to the on-disk location of each document.

Sort Order

NameDescription
$naturalA special sort order that orders documents using the order of documents on disk.