MongoDB CRUD

All queries in MongoDB address a single collection.
You can modify the query to impose limits, skips, and sort orders.
The order of documents returned by a query is not defined unless you specify a sort().
Operations that modify existing documents (i.e. updates) use the same query syntax as queries to select documents to update.
In aggregation pipeline, the $match pipeline stage provides access to MongoDB queries.
MongoDB provides a db.collection.findOne() method as a special case of find() that returns a single document.

Cursor Information

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

You can use the command cursorInfo to retrieve the following information on cursors:
total numberof open cursors
size ofthe client cursors in current use
numberof timed out cursors sincethelast server restart
Consider the following example:
db.runCommand( { cursorInfo: 1 } )
The resultfromthe command returns the following document:
{
"totalOpen" : <number>,
"clientCursors_size" : <number>,
"timedOut" : <number>,
"ok" : 1
}

Analyze Query Performance
To use the explain() method, call the method on a cursor returned by find().

With an upsert, applications can decide between performing an update or an insert operation using just a single call. Both the update() method and the save() method can perform an upsert. See update() and save() for details on performing an upsert with these methods.

With additional clauses, you can specify precise conditions for matching documents.

In the following example, the compound query document selects all documents in the collection where the value of the type field is 'food' and either the qty has a value greater than ($gt) 100 or the value of the price field is less than ($lt) 9.95: