The MongoDB cursor object provides a BatchSize
property and and Limit
property but I can't seem to find any definitive information that properly clarifies the difference between the two.
I'm using the .Net driver, for what it's worth.
In most cases, modifying the batch size will not affect the user or the application, as mongosh and most drivers return results as if MongoDB returned a single batch. The number of documents to return per batch.
This document provides a collection of hard and soft limitations of the MongoDB system. The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth.
The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.
Specifying 1 or a negative number is analogous to using the limit () method. The following example sets the batch size for the results of a query (i.e. find ()) to 10. The batchSize () method does not change the output in mongosh, which, by default, iterates over the first 20 documents.
Limit is the total number of results you want. If your query would return one thousand documents but you only want 5 you can use Limit to limit the size of the total result.
BatchSize is the number of results that should be returned in each batch. If your result set for a query is large MongoDB isn't going to return all the results in one batch. It will return a subset of the total result, then the cursor will send a getMore message to the server when it needs the next batch of results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With