MongoDB Cheat Sheet
by Ovidiu Anicai (ovi_mihai) via cheatography.com/4776/cs/916/ Basic commands mongo
Start Mongo
show dbs
Finds - db.collection
Mongo Queries
.find()
_id
Search by ID
key: value
Search through key-value combin
n" (first 10)
Show databases
use mydb
User database named "mydb"
db
Show selected database
help
Get help
show collections
Show collections from a database
Displays documents from "collectio
it
Type "it" to see more documents
ation
after the prev command
{ subkey: value
.find( query [,
Find all documents by conditions,
}
fields] )
with optional fields selection
.findOne( query
Find one document by conditions
) .find( query )
$in : [ e1, e2, ..
Search with subdocument
Search IN Array
] queries are represented through JSON objects
Find n document by conditions
.limit( n:number )
Cheatographer
.find() .pretty()
Format results in Mongo Shell
.find() .sort( key :
Sort by key in ascending (1) or
1|-1 )
descending (-1) order
.find() .skip( 5 )
Skip 5 documents (similar to offset)
Cheat Sheet
Sponsor
Ovidiu Anicai (ovi_mihai)
This cheat sheet was published on 27th March, 2013
FeedbackFair, increase your conversion rate today!
cheatography.com/ovi-mihai/
and was last updated on 27th March, 2013.
Try it free!
0v1.ro
http://www.FeedbackFair.com