> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# cursor.batchSize() (mongosh method)

## Definition

**Important: mongosh Method**

This page documents a [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) method. This is *not* the documentation for a language-specific driver, such as Node.js.

For MongoDB API drivers, refer to the language-specific [MongoDB driver documentation.](https://www.mongodb.com/docs/drivers/)

The maximum number of documents that can be returned in each batch of a query result. By default, the initial batch size is the lesser of `101` documents or 16 mebibytes (MiB) worth of documents. Subsequent batches have a maximum size of 16 MiB. This option can enforce a smaller limit than 16 MiB, but not a larger one. When set, the `batchSize` is the lesser of `batchSize` documents or 16 MiB worth of documents.

In sharded clusters, `mongos` does not forward the `batchSize` value to individual shards. Subsequent [`getMore`](https://www.mongodb.com/docs/manual/reference/command/getmore.md#mongodb-dbcommand-dbcmd.getMore) operations in a sharded cluster return up to 16 MiB of documents per batch, regardless of the configured `batchSize`.

A `batchSize` of `0` means that the cursor is established, but no documents are returned in the first batch.

**Note:**

If the batch size is too large, the cursor allocates more resources than it requires, which can negatively impact query performance.  If the batch size is too small, the cursor requires more network round trips to retrieve the query results, which can negatively impact query performance.

Adjust `batchSize` to a value appropriate to your database, load, and application needs.

The [`batchSize()`](https://www.mongodb.com/docs/manual/reference/method/cursor.batchsize.md#mongodb-method-cursor.batchSize) method takes the following field:

| Field | Type | Description |
| --- | --- | --- |
| `size` | integer | The maximum number of documents that can be returned in each batch of a query result. The default initial batch size is the lesser or `101` documents or 16 mebibytes (MiB) worth of documents. Subsequent batches have a maximum size of 16 MiB. This option can enforce a smaller limit than 16 MiB, but not a larger one. The default applies to drivers and Mongo Shell. For details, see [Cursor Batches.](https://www.mongodb.com/docs/manual/core/cursors.md#std-label-cursor-batches) |

## Compatibility

This method is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

**Note:**

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Example

The following example sets `batchSize` for the results of a query (specifically, [`find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#mongodb-method-db.collection.find)) to `10`:

```javascript
db.inventory.find().batchSize(10)
```

## Learn More

- [Cursor Batches](https://www.mongodb.com/docs/manual/core/cursors.md#std-label-cursor-batches)

- [`cursor.next()`](https://www.mongodb.com/docs/manual/reference/method/cursor.next.md#mongodb-method-cursor.next)

- [`getMore`](https://www.mongodb.com/docs/manual/reference/command/getmore.md#mongodb-dbcommand-dbcmd.getMore)
