Show Menu


Basic commands

Start Mongo
show dbs
Show databases
use mydb
User database named "­myd­b"
Show selected database
Get help
show collec­tions
Show collec­tions from a database

Finds - db.col­lection

Displays documents from "­col­lec­tio­n" (first 10)
Type "­it" to see more documents after the prev command
Find all documents by condit­ions, with optional fields selection
Find one document by conditions
Find n document by conditions
Format results in Mongo Shell
Sort by key in ascending (1) or descending (-1) order
Skip 5 documents (similar to offset)

Modify - db.col­lection

.insert(document(s) [,options])
Insert a new document or multiple docume­nts(if provided an array of documents) in the collec­tion. Options: writeC­oncern, ordered
.inser­tOn­e(d­ocu­ment, [,opti­ons])
Same as insert from 3.2
.inser­tMa­ny(­array of documents, [,opti­ons])
Same as in sert from 3.2
.updat­e(q­uery, update [,opti­ons])
Update the documents matched by the query. See update operators. Options: upsert­(insert if no match), multi(aply to multiple elements), writeC­oncern
.remov­e(query [,opti­ons])
Remote some documents from a collec­tion. {} for all. options: {justOne, writeC­oncern}
.delet­eOn­e(q­uery), delete­Man­y(q­uery)
Similar to remove


Search by ID
key: value
Search through key-value combin­ation
{ subkey: value }
Search with subdoc­ument
$in : [ e1, e2, .. ]
Search IN Array
queries are repres­ented through JSON objects

Query Selectors : Element

Check if property exists or not
Checks if a property divided by D has the specified R
Checks if property is the specified type

Query Selectors : Comparison

Greater then Val
Greater then equals Val
Lower then Val
Lower then equals Val
All Array elements are included in field array value
Elements with values contained in Array
Elements with values Not contained in Array
Not equal
Val can be any Scalar Integer, String, Date, etc

Query Selectors : Logical

AND operation between all AOE expres­sions
all AOE expres­sions must fail
Negate a SubDoc­ument (doesn't work with $regex)
OR operation between all AOE expres­sions
Expr = Expression
AOE = Array Of Expres­sions
( eg: Expression = price : 20 )


Hello, could you update this cheatsheet with insert, update and remove operations?

I'm on it, but I have so little time this days :(

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          MySQL Cheat Sheet
          SQL Server Cheat Sheet

          More Cheat Sheets by ovi_mihai

          JIRA Cheat Sheet