Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Limit and BatchSize in MongoCursor?

Tags:

.net

mongodb

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.

like image 475
Nathan Ridley Avatar asked Nov 22 '11 23:11

Nathan Ridley


People also ask

What happens if I change the batch size in mongosh?

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.

What are the limitations of the MongoDB system?

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.

What is the maximum BSON document size in MongoDB?

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.

How to specify 1 or a negative number in mongosh?

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.


1 Answers

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.

like image 102
Bernie Hackett Avatar answered Sep 19 '22 11:09

Bernie Hackett