What is the difference between Limit and BatchSize in MongoCursor?

The MongoDB cursor object provides the BatchSize property and the Limit property, but I cannot find the final information that correctly explains the difference between the two.

I am using the .Net driver for what it costs.

+4
source share
2 answers

Limit is the total number of desired results. If your query returns a thousand documents, but you only want 5, you can use Limit to limit the size of the final result.

BatchSize - the number of results to be returned in each batch. If your result for the query is large, MongoDB will not return all the results in one batch. It will return a subset of the final result, then the cursor will send a getMore message to the server when it needs the next batch of results.

+9
source

I got this from the MongoDB documentation:

[batchSize] limits the number of items returned in one batch. The cursor usually selects the result package of objects and saves them locally. If batchSize is positive, it represents the size of each batch of objects that were received. It can be tuned to optimize performance and limit data transfer. If batchSize is negative, it will limit the returned numeric objects that correspond to the maximum batch size limit (usually 4 MB), and the cursor will be closed. For example, if batchSize is -10, then the server will return a maximum of 10 documents and as many as can fit in 4 MB, and then close the cursor. Please note that this function differs from limit () in that the documents must correspond to the maximum size and eliminates the need to send a request to close the server part of the cursor. The batch size can be changed even after the cursor is repeated, in which case the setting will be applied the next time the batch is retrieved.

Here's a link to a glossary of terms in which this happened: http://api.mongodb.org/java/2.6/com/mongodb/DBCursor.html#batchSize(int )

+5
source

Source: https://habr.com/ru/post/1382603/


All Articles