Definition
Compatibility
This command is available in deployments hosted in the following environments:
MongoDB 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.
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
The command has the following syntax:
db.runCommand( { getMore: <long>, collection: <string>, batchSize: <int>, maxTimeMS: <int>, comment: <any> } )
Command Fields
The command accepts the following fields:
Field | Type | Description |
|---|---|---|
| long | The cursor identifier. |
| string | The name of the collection over which the cursor is operating. |
| positive integer | Optional. The maximum number of documents that can be returned in each batch of a query result. If |
| non-negative integer | Optional. Specifies the maximum time for the server to wait for new documents that match a tailable cursor query on a capped collection.
MongoDB terminates operations that exceed their allotted time limit using the same mechanism as
|
| any | Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:
A comment can be any valid BSON type (string, integer, object, array, etc). If omitted, |
Output
The command returns a document that contains the cursor information as well as the next batch.
For example, running getMore on a cursor created by a find operation on a sharded cluster returns a document similar to this output:
{ "cursor" : { "id" : Long("678960441858272731"), "ns" : "test.contacts", "nextBatch" : [ { "_id" : ObjectId("5e8e501e1a32d227f9085857"), "zipcode" : "220000" } ], "partialResultsReturned" : true, "postBatchResumeToken": "< Resume Token >" }, "ok" : 1, "operationTime" : Timestamp(1586385239, 2), "$clusterTime" : { "clusterTime" : Timestamp(1586385239, 2), "signature" : { "hash" : BinData(0,"lLjejeW6AQGReR9x1PD8xU+tP+A="), "keyId" : Long("6813467763969884181") } } }
Field | Description |
|---|---|
| Contains the cursor information, including the cursor ID as well as the If The |
| Indicates whether the command has succeeded ( |
In addition to these fields, the db.runCommand() response includes the following information for replica sets and sharded clusters:
$clusterTimeoperationTime
See db.runCommand() Response for details.
Behavior
Access Control
If authentication is enabled, you can only run getMore against cursors you created.
Sessions
For cursors created inside a session, you cannot call getMore outside the session.
Similarly, for cursors created outside of a session, you cannot call getMore inside a session.
Transactions
Errors
Starting in MongoDB 8.2, the cursor identifier must match the name of the cursor that operates on the specified collection. If the collection does not have a cursor with the specified cursor identifier, getMore returns an error.
Slow Queries
Starting in MongoDB 5.1, when a getMore command is logged as a slow query, the queryHash and planCacheKey fields are added to the slow query log message and the profiler log message.
Starting in MongoDB 8.0, the existing queryHash field is duplicated in a new field named planCacheShapeHash. If you're using an earlier MongoDB version, you'll only see the queryHash field. Future MongoDB versions will remove the deprecated queryHash field, and you'll need to use the planCacheShapeHash field instead.