mongodbHow to use the limit operator in MongoDB?
The limit()
operator in MongoDB is used to limit the number of documents returned in a query. It is used in conjunction with the find()
method.
Example
db.collection.find().limit(5)
This will return the first 5 documents from the collection.
Code explanation
db.collection.find()
: This is the method used to query the collection..limit(5)
: This is the limit operator, which limits the number of documents returned to 5.
Helpful links
More of Mongodb
- How to check the version of MongoDB?
- How to use watch in MongoDB?
- How to update one document in MongoDB?
- How to update many documents in MongoDB?
- How to use MongoDB queue?
- How to create a many to many relation in MongoDB?
- How to insert new document into MongoDB?
- How to use hint in MongoDB?
- How to work with time series data in MongoDB?
- How to use unwind in MongoDB?
See more codes...