DEV Community

Cover image for The Surprising Power of MongoDB's Limit(0) Method
aniketcodes
aniketcodes

Posted on

The Surprising Power of MongoDB's Limit(0) Method

The limit() method in MongoDB allows you to specify the maximum number of documents that should be returned in a query result. By default, the limit() method returns all documents in a collection.
But what if you use limit(0)?
Instead of returning 0 records, it will return all the records present in the collection.

Image description

This happens because MongoDB treats 0 in limit() as infinity.

Top comments (0)