MongoDB – CRUD Operations

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability.

Quick Command reference:

CRUD operations

Creating documents:

MongoDB is able to provide few options to import documents into collection: insertOne, insert, update (upsert) and save.


  • A boolean acknowledged as true if the operation ran with write concern or false if write concern was disabled.

If you want to add multiple documents at once, MongoDB provides insertMany with ordered (default – it will stop at first error) or unordered mode – even there are errors MongoDB will continue the insert with the next document.


[code language=”javascript”][/code]

Update with upsert = true

If set to true, creates a new document when no document matches the query criteria. The default value is false, which does not insert a new document when no match is found.

You can use save command to quick update/insert a document into collection:

Reading documents:


cursor.objsLeftInBatch() returns the number of objects remaining in batch.

Logical operators:

Array match:

Update operators:

where optional options_document has any one or more of the following optional parameters:




Data aggregation:

Please follow this link with additional info about Data Aggregation.

Users management:

Reduce function:

and the output:

Pattern matching with $regex = equivalent to “like %” in RDBMS

Pattern matching without $regex:


Map-Reduce is a data processing paradigm for condensing large volumes of data into useful aggregated results.


Source: mongodb

Additional links:1.MongoDB card reference.pdf