WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

MongoDB - Limit Records


MongoDB - Limit Records learn how to limit records using MongoDB.

The Limit() Method

To limit the records in MongoDB, you need to use limit() method.The method accepts one number type argument

Syntax

There are following basic syntax of limit() method
>db.COLLECTION_NAME.find().limit(NUMBER)

Example

Consider the collection myycol has the following data.
{ "_id" : ObjectId(LeDrYka$3q9w5), "title":"MongoDB"}
{ "_id" : ObjectId(LeDrYka$3q9w6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(LeDrYka$3q9w7), "title":"Welookups"}
Following example will display only two documents while querying the document.
>db.mycol.find({},{"title":1,_id:0}).limit(2)
{"title":"MongoDB Overview"}
{"title":"NoSQL Overview"}
>




Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.