getMore

On this page本页内容

Definition定义

getMore

Use in conjunction with commands that return a cursor, e.g. find and aggregate, to return subsequent batches of documents currently pointed to by the cursor.与返回游标的命令结合使用,例如findaggregate,以返回游标当前指向的后续文档批。

Syntax语法

The getMore command has the following form:getMore命令的格式如下:

db.runCommand(
   {
      "getMore": <long>,
      "collection": <string>,
      "batchSize": <int>,
      "maxTimeMS": <int>,
      "comment": <any>
   }
)

Command Fields命令字段

The command accepts the following fields:该命令接受以下字段:

Field字段Type类型Description描述
getMorelongThe cursor id.游标id。
collectionstringThe name of the collection over which the cursor is operating.游标正在其上操作的集合的名称。
batchSizepositive integerOptional. 可选。The number of documents to return in the batch.批处理中要返回的文档数。
maxTimeMSnon-negative integer

Optional. 可选。Specifies a time limit in milliseconds for processing operations on a cursor. 指定处理游标操作的时间限制(以毫秒为单位)。If you do not specify a value for maxTimeMS, operations will not time out. 如果未指定maxTimeMS的值,操作将不会超时。A value of 0 explicitly specifies the default unbounded behavior.0明确指定默认的无界行为。

MongoDB terminates operations that exceed their allotted time limit using the same mechanism as db.killOp(). MongoDB使用与db.killOp()相同的机制终止超过分配时间限制的操作。MongoDB only terminates an operation at one of its designated interrupt points.MongoDB仅在其指定的中断点之一终止操作。

commentany

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).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

Note注意

If omitted, getMore inherits any comment set on the originating find or aggregate command.如果省略,getMore将继承原始findaggregate命令上的任何注释集。

New in version 4.4.在版本4.4中新增

Output输出

The command returns a document that contains the cursor information as well as the next batch.该命令返回包含游标信息以及下一批的文档。

For example, a document similar to the one below may be returned when getMore is run on a cursor that was originally created by a find operation on a sharded cluster:

{
   "cursor" : {
      "id" : NumberLong("678960441858272731"),
      "ns" : "test.contacts",
      "nextBatch" : [
         {
            "_id" : ObjectId("5e8e501e1a32d227f9085857"),
            "zipcode" : "220000"
         }
      ],
      "partialResultsReturned" : true
   },
   "ok" : 1,
   "operationTime" : Timestamp(1586385239, 2),
   "$clusterTime" : {
      "clusterTime" : Timestamp(1586385239, 2),
      "signature" : {
         "hash" : BinData(0,"lLjejeW6AQGReR9x1PD8xU+tP+A="),
         "keyId" : NumberLong("6813467763969884181")
      }
   }
}
Field字段Description描述
cursor

Contains the cursor information, including the cursor id as well as the nextBatch of documents.

Starting in 4.4, if the cursor from a find command returns partial results due to the unavailability of the queried shard(s), the cursor document includes a partialResultsReturned field. To return partial results, rather than error, due to the unavailability of the queried shard(s), the initial find command must run with allowPartialResults set to true. See allowPartialResults.

If the queried shards are initially available for the find command but one or more shards become unavailable in subsequent getMore commands, only the getMore commands run when a queried shard or shards are unavailable include the partialResultsReturned flag in the output.

"ok"Indicates whether the command has succeeded (1) or failed (0).

In addition to the aforementioned getMore-specific fields, the db.runCommand() includes the following information for replica sets and sharded clusters:

  • $clusterTime
  • operationTime

See db.runCommand() Results for details.有关详细信息,请参阅db.runCommand()结果

Behavior行为

Access Control访问控制

If authentication is turned on, you can only issue a getMore against cursors you created.

Sessions

New in version 4.0.在版本4.0中新增

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

New in version 4.0.在版本4.0中新增

For multi-document transactions:对于多文档事务

  • For cursors created outside of a transaction, you cannot call getMore inside the transaction.对于在事务外部创建的游标,不能在事务内部调用getMore
  • For cursors created in a transaction, you cannot call getMore outside the transaction对于在事务中创建的游标,不能在事务外部调用getMore.

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.

←  getLastErrorinsert →