Docs Menu

getMore

getMore

Use in conjunction with commands that return a cursor. For example, find and aggregate, to return subsequent batches of documents currently pointed to by the cursor.

이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하십시오.

명령은 다음과 같은 구문을 가집니다:

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

이 명령에는 다음과 같은 필드를 사용할 수 있습니다.

필드
유형
설명

getMore

long

The cursor identifier.

collection

문자열

The name of the collection over which the cursor is operating.

batchSize

positive integer

Optional. The number of documents to return in the batch.

If batchSize is not set, getMore returns up to 16 mebibytes of data. If batchSize is set, getMore returns the smaller of 16 mebibytes of data or batchSize documents.

maxTimeMS

non-negative integer

선택 사항.

Specifies the maximum time for the server to wait for new documents that match a 테일 커서(tailable cursor) query on a 고정 사이즈 컬렉션.. maxTimeMS on a getMore for a tailable awaitData cursor is considered the same as maxAwaitTimeMS(). Drivers will only set this value on getMore for a tailable cursor on a capped collection with awaitData set to true. Otherwise, the command that creates the cursor sets maxTimeMS, which is the maximum amount of time that the initial operation, and any subsequent getMore operations, can spend cumulatively executing the query. For tailable cursors with awaitData set to true, the following is true:

  • If no value is provided, the wait time defaults to 1 (1000 milliseconds).

  • maxTimeMS on getMore specifies the maximum amount of time MongoDB waits for new documents to be inserted into the capped collection for that specific getMore command.

  • maxTimeMS is set individually by the driver for each call to getMore.

MongoDB terminates operations that exceed their allotted time limit using the same mechanism as db.killOp(). MongoDB only terminates an operation at one of its designated interrupt points.

  • You cannot set maxTimeMS when calling getMore on a non-tailable cursor. Instead, set it using maxTimeMS() when you create the cursor.

  • To use getMore with maxTimeMS on a tailable cursor, enable awaitData when you create the cursor using cursor.tailable().

  • 설정 maxTimeMS on the command that creates a cursor only sets the time limit for that operation. Use getMore to set a limit on further operations.

  • You can set or omit maxTimeMS for each call to getMore, and you don't have to use the same value.

  • For a tailable cursor, a timeout on getMore retains the documents accumulated before the timeout occurred in the cursor. For a non-tailable cursor, a timeout raises an error.

comment

any

선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.

댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다.

If omitted, getMore inherits any comment set on the originating find or aggregate command.

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" : NumberLong("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" : NumberLong("6813467763969884181")
}
}
}
필드
설명

cursor

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

쿼리된 샤드 를 사용할 find 수 없기 때문에(또는 후속 getMore 명령)이 부분 결과를 반환하는 경우 partialResultsReturned 찾기 출력에는 표시기 필드 포함됩니다. 쿼리된 샤드를 초기 find 명령에 사용할 수 있지만 후속 getMore 명령에 하나 이상의 샤드를 사용할 수 없게 되는 경우, 샤드를 사용할 수 없는 동안 실행 getMore 명령만 출력에 partialResultsReturned 가 포함됩니다. .

The postBatchResumeToken field can be used with the $changeStream pipeline to start or resume a change stream from this point.

"ok"

명령에 성공했는지(1) 또는 실패했는지(0) 여부를 나타냅니다.

In addition to these fields, the db.runCommand() response includes the following information for replica sets and sharded clusters:

  • $clusterTime

  • operationTime

See db.runCommand() Response for details.

If 인증 is enabled, you can only run getMore against cursors you created.

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.

다중 문서 트랜잭션의 경우:

  • For cursors created outside of a transaction, you cannot call getMore inside the transaction.

  • For cursors created in a transaction, you cannot call getMore outside the transaction.

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.

MongoDB 8.0부터 기존 queryHash 필드 planCacheShapeHash라는 새 필드 에 중복됩니다. 이전 MongoDB 버전을 사용하는 경우 queryHash 필드 만 표시됩니다. 향후 MongoDB 버전에서는 더 이상 사용되지 않는 queryHash 필드 제거 될 예정이며, 대신 planCacheShapeHash 필드 사용해야 합니다.