MongoDB – limit() method

MongoDB limit() Method Use limit() method to show the limited number of documents in a collection with find() method. Syntax: db.COLLECTION_NAME.find().limit(NUMBER) Example: For example users collection have 19 documents. Now you need to get only first 2 documents from collection. > db.users.find().limit(2); Output: { “_id” : ObjectId(“59a01b102427abe3470644db”), “id” : 1001, “user_name” : “rahul”, “name” : [ { “first_name” : “Rahul” }, { “middle_name” : “” }, { “last_name” : “Kumar” } ], “email” : “[email protected]”, “designation” : “Founder and CEO”, “location” : “India” } { “_id” : ObjectId(“59a01b2f2427abe3470644dc”), “id” :…

Read More