MongoDB -Advanced Operations
limit() To limit the records in MongoDB, you need to use limit() method
>db.COLLECTION_NAME.find().limit(NUMBER)
Skip() used to skip the number of documents.
>db.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)
sort() specify sorting order. 1 is used for ascending order while -1 is used for descending order.
>db.COLLECTION_NAME.find().sort({KEY:1})
aggregate() aggregation in MongoDB, you should use aggregate() method.
>db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)
AGGREGATE_OPERATION = $sum, $avg, $min, $max, $push, $addToSet, $first, $last
db.collection.save()
Updates an existing document or inserts a new document, depending on its document parameter.
db.products.save( { item: "book", qty: 40 } )
help() uses to guide you how to do things in MongoDB.
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory,
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
PREVIOUSDocument Operations