MongoDB Cheat Sheet
by Ovidiu Anicai (ovi_mihai) via cheatography.com/4776/cs/916/
Basic commands Finds - db.collection Mongo Queries
mongo Start Mongo .find() Displays documents from "collectio _id Search by ID
n" (first 10)
show dbs Show databases key: value Search through key-value combin
it Type "it" to see more documents ation
use mydb User database named "mydb"
after the prev command { subkey: value Search with subdocument
db Show selected database
.find( query [, Find all documents by conditions, }
help Get help
fields] ) with optional fields selection
$in : [ e1, e2, .. Search IN Array
show collections Show collections from a database
.findOne( query Find one document by conditions ]
)
queries are represented through JSON objects
.find( query ) Find n document by conditions
.limit( n:number
)
.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)
Cheatographer 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