Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information

Returning documents

From NoSQLZoo
Revision as of 00:13, 9 April 2018 by 40166222 (talk | contribs) (Convert py3 -> mongo)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Return all documents
db.world.find()
db.world.aggregate([{"$match":{}}])
Returning the first document
db.world.findOne()
db.world.find()[0]
db.world.find().limit(1)
db.world.aggregate([{"$limit":1}])
Returning the nth document
let n = 50;
db.world.find()[n-1]
db.world.find().skip(n-1).limit(1)
db.world.aggregate([{"$skip":n-1},{"$limit":1}])
Returning the last document
db.world.find()[db.world.count()-1]
db.world.find().skip(db.world.count()-1).limit(1)
db.world.aggregate([{"$skip":db.world.count()-1},{"$limit":1}])