Database Reference
In-Depth Information
Limiting the number of records returned
Another trick to improve the performance of the
find
operations is limiting the output re-
cords to specific numbers of items. Thus, the engine only returns a subset of all records and
a client downloads a smaller piece of data. Both of these methods together can boost the
overall performance of an operation.
To limit the output to smaller items, you can use the
limit()
function, similar to the fol-
lowing function:
db.testcollection.find().limit(2)
In the preceding example, the database engine returns only two records from all the inser-
ted records based on the given sort options.