Limit The Query
This query method specifies a maximum number of documents for a cursor to return.
Example:
db. article. find({author : "devil" }). limit(2) . pretty()
Output :
[
{
_id: ObjectId('60095b8a3fc110f90873ce2c'),
title: 'Tree',
author: 'devil',
level: 'high',
length: 1000,
example: 10
},
{
_id: ObjectId('60095b8d3fc110f90873ce2e'),
title: 'Segment Tree',
author: 'devil',
level: 'very high',
length: 500,
example: 20
}
]
This query method is simply the extension of the find method only provide a result at a maximum limited number(here is 2)
- Query to find record having given attribute: find({author : “devil” })
- Query to limit result: limit( 2).
What is a MongoDB Query?
MongoDB Query is a fundamental aspect of MongoDB that allows users to fetch data from the database. Similar to SQL queries in traditional databases, MongoDB queries provide simplicity and flexibility in retrieving specific data based on certain criteria or conditions.
In this article, We will learn about the MongoDB Query in detail by performing various Queries on document of MongoDB collection and so on.
Contact Us