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

Returning documents

From NoSQLZoo
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}])