Skip to content

Commit 2a47c20

Browse files
authored
DOCSP-15109 Resume Tokens v5.0 backport (#2095)
* DOCSP-15109 merge from upstream * DOCSP-15109 Removes 6.0 change event field
1 parent c544306 commit 2a47c20

File tree

2 files changed

+130
-14
lines changed

2 files changed

+130
-14
lines changed

source/changeStreams.txt

Lines changed: 124 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ Change streams are resumable by specifying a resume token to either
743743
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
744744

745745
You can resume a change stream after a specific event by passing a resume token
746-
to ``resumeAfter`` when opening the cursor. For the resume token, use the
747-
``_id`` value of the :ref:`change stream event document <change-stream-output>`.
746+
to ``resumeAfter`` when opening the cursor.
747+
748748
See :ref:`change-stream-resume-token` for more information on the resume token.
749749

750750
.. important::
@@ -941,9 +941,9 @@ You can start a new change stream after a specific event by passing a resume
941941
token to ``startAfter`` when opening the cursor. Unlike
942942
:ref:`resumeAfter <change-stream-resume-after>`, ``startAfter`` can
943943
resume notifications after an :ref:`invalidate event <change-event-invalidate>`
944-
by creating a new change stream. For the resume token, use the ``_id`` value of
945-
the :ref:`change stream event document <change-stream-output>`. See
946-
:ref:`change-stream-resume-token` for more information on the resume token.
944+
by creating a new change stream.
945+
946+
See :ref:`change-stream-resume-token` for more information on the resume token.
947947

948948
.. important::
949949

@@ -956,22 +956,133 @@ the :ref:`change stream event document <change-stream-output>`. See
956956
Resume Tokens
957957
~~~~~~~~~~~~~
958958

959-
The ``_id`` value of a :ref:`change stream event document
960-
<change-stream-output>` acts as the resume token:
959+
The resume token is available from multiple sources:
960+
961+
.. list-table::
962+
:header-rows: 1
963+
:stub-columns: 1
964+
:widths: 20 80
965+
966+
* - Source
967+
- Description
968+
969+
* - :ref:`Change Events <change-event-resume-token>`
970+
- Each change event notification includes a resume token
971+
on the ``_id`` field.
972+
973+
* - :ref:`Aggregation <aggregate-resume-token>`
974+
- The :pipeline:`$changeStream` aggregation stage includes
975+
a resume token on the ``cursor.postBatchResumeToken`` field.
976+
977+
This field only appears when using the :dbcommand:`aggregate`
978+
command.
979+
980+
* - :ref:`Get More <getMore-resume-token>`
981+
- The :dbcommand:`getMore` command includes a resume token on the
982+
``cursor.postBatchResumeToken`` field.
983+
984+
.. versionchanged:: 4.2
985+
986+
.. include:: /includes/extracts/4.2-changes-change-stream-modification-error.rst
987+
988+
.. _change-event-resume-token:
989+
990+
Resume Tokens from Change Events
991+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
992+
993+
Change event notifications include a resume token on the ``_id`` field:
994+
995+
.. code-block:: json
996+
:copyable: false
997+
:emphasize-lines: 2-4
961998

962-
.. code-block:: none
963999

9641000
{
965-
"_data" : <BinData|hex string>
1001+
"_id": {
1002+
"_data": "82635019A0000000012B042C0100296E5A1004AB1154ACACD849A48C61756D70D3B21F463C6F7065726174696F6E54797065003C696E736572740046646F63756D656E744B65790046645F69640064635019A078BE67426D7CF4D2000004"
1003+
},
1004+
"operationType": "insert",
1005+
"clusterTime": Timestamp({ "t": 1666193824, "i": 1 }),
1006+
"collectionUUID": new UUID("ab1154ac-acd8-49a4-8c61-756d70d3b21f"),
1007+
"fullDocument": {
1008+
"_id": ObjectId("635019a078be67426d7cf4d2"'),
1009+
"name": "Giovanni Verga"
1010+
},
1011+
"ns": {
1012+
"db": "test",
1013+
"coll": "names"
1014+
},
1015+
"documentKey": {
1016+
"_id": ObjectId("635019a078be67426d7cf4d2")
1017+
}
9661018
}
9671019

968-
.. include:: /includes/extracts/changestream-resume-token-versions-4.2-greater.rst
9691020

970-
.. include:: /includes/extracts/changestream-resume-token-hex-change.rst
1021+
.. _aggregate-resume-token:
9711022

972-
.. tip::
1023+
Resume Tokens from ``aggregate``
1024+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1025+
1026+
When using the :dbcommand:`aggregate` command, the :pipeline:`$changeStream`
1027+
aggregation stage includes a resume token on the
1028+
``cursor.postBatchResumeToken`` field:
1029+
1030+
.. code-block:: json
1031+
:copyable: false
1032+
:emphasize-lines: 4-6
1033+
1034+
{
1035+
"cursor": {
1036+
"firstBatch": [],
1037+
"postBatchResumeToken": {
1038+
"_data": "8263515EAC000000022B0429296E1404"
1039+
},
1040+
"id": Long("4309380460777152828"),
1041+
"ns": "test.names"
1042+
},
1043+
"ok": 1,
1044+
"$clusterTime": {
1045+
"clusterTime": Timestamp({ "t": 1666277036, "i": 1 }),
1046+
"signature": {
1047+
"hash": Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
1048+
"keyId": Long("0")
1049+
}
1050+
},
1051+
"operationTime": Timestamp({ "t": 1666277036, "i": 1 })
1052+
}
1053+
1054+
.. _getMore-resume-token:
1055+
1056+
Resume Tokens from ``getMore``
1057+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1058+
1059+
The :dbcommand:`getMore` command also includes a resume token on the
1060+
``cursor.postBatchResumeToken`` field:
1061+
1062+
.. code-block:: json
1063+
:copyable: false
1064+
:emphasize-lines: 4-6
1065+
1066+
{
1067+
"cursor": {
1068+
"nextBatch": [],
1069+
"postBatchResumeToken": {
1070+
"_data": "8263515979000000022B0429296E1404"
1071+
},
1072+
"id": Long("7049907285270685005"),
1073+
"ns": "test.names"
1074+
},
1075+
"ok": 1,
1076+
"$clusterTime": {
1077+
"clusterTime": Timestamp( { "t": 1666275705, "i": 1 } ),
1078+
"signature": {
1079+
"hash": Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
1080+
"keyId": Long("0")
1081+
}
1082+
},
1083+
"operationTime": Timestamp({ "t": 1666275705, "i": 1 })
1084+
}
9731085

974-
.. include:: /includes/extracts/4.2-changes-change-stream-modification-error.rst
9751086

9761087
Use Cases
9771088
---------

source/reference/command/getMore.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ For example, a document similar to the one below may be returned when
127127
"zipcode" : "220000"
128128
}
129129
],
130-
"partialResultsReturned" : true
130+
"partialResultsReturned" : true,
131+
"postBatchResumeToken": "< Resume Token >"
131132
},
132133
"ok" : 1,
133134
"operationTime" : Timestamp(1586385239, 2),
@@ -169,6 +170,10 @@ For example, a document similar to the one below may be returned when
169170
shards are unavailable include the ``partialResultsReturned``
170171
flag in the output.
171172

173+
The ``postBatchResumeToken`` field can be used with the
174+
:pipeline:`$changeStream` pipeline to start or resume
175+
a change stream from this point.
176+
172177
* - ``"ok"``
173178

174179
- Indicates whether the command has succeeded (``1``) or failed

0 commit comments

Comments
 (0)