We have number of meta operation in addition to the MongoDB Query Operators to modify the output or behaviour of a query.
db.collection.find( { <query> } )._addSpecial( <option> ) db.collection.find( { $query: { <query> }, <option> } )
The comment operator makes it possible to add a comment to a query in any context.
Syntax:
db.collection.find( { <query> } )._addSpecial( "$comment", <comment> )
The explain modifier provides details about the query plan. It returns a file that describes the process and indexes used to return the query. It may give useful insight when attempting to optimize a query.
Syntax:
db.example.find( { $query: {}, $explain: 1 } )
This operator is deprecated in the mongo shell now. The hint operator attaches the optimizer to use the declared index to fulfill the query. It is also used for testing query performance and indexing strategies.
Syntax:
db.users.find().hint( { age: 1 } )
The max operator is deprecated in mongo shell since v3.2. It defines a max value to specify the exclusive upper bound for the given index in order to limit the results of find ().
Syntax:
db.example.find( { <query> } ).max( { field1: <max value>, ... fieldN: <max valueN> } )
It is also deprecated since v3.2. It defines a cumulative time in ms for processing operations on the cursor.
Syntax:
db.collection.find().maxTimeMS(100)
The min operator is used to find a minimum value to declare the included lower bound for a specified index to constrain the results of find ().
Syntax:
db.collection.find( { <query> } ).min( { field1: <min value>, ... fieldN: <min valueN>} )
The orderby operator arranges the results of a query in ascending or descending order.
Syntax:
db.collection.find().sort( { age: -1 } )
It forcefully interprets an expression as a query using MongoDB.
Syntax:
db.collection.find( { $query: { age : 25 } } ) db.collection.find( { age : 25 } )
The return key returns the index fields for the results of the query. If returnkey operator is set to true then the returned documents will not contain any fields.
Syntax:
db.collection.find( { <query> } )._addSpecial( "$returnKey", true ) db.collection.find( { $query: { <query> }, $returnKey: true } )
The showDiskLoc operator adds a field to the resultant documents. The value of the added diskLoc field is a document that contains the disk location details.
Syntax:
"$diskLoc": { "file": <int>, "offset": <int> }
The natural operator is a special sort order operator that arranges the documents using the order of documents on disk using the cursor.hint ().