Skip to content

Commit 1008799

Browse files
authored
DOCSP-15109 Fixes cherry-pick (#2098)
1 parent b6c976b commit 1008799

File tree

2 files changed

+133
-12
lines changed

2 files changed

+133
-12
lines changed

source/changeStreams.txt

Lines changed: 127 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ Change streams are resumable by specifying a resume token to either
643643
``resumeAfter`` for Change Streams
644644
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
645645

646+
You can resume a change stream after a specific event by passing a resume token
647+
to ``resumeAfter`` when opening the cursor.
648+
649+
See :ref:`change-stream-resume-token` for more information on the resume token.
650+
646651
.. container::
647652

648653
.. tabs-pillstrip:: languages
@@ -822,9 +827,9 @@ You can start a new change stream after a specific event by passing a resume
822827
token to ``startAfter`` when opening the cursor. Unlike
823828
:ref:`resumeAfter <change-stream-resume-after>`, ``startAfter`` can
824829
resume notifications after an :ref:`invalidate event <change-event-invalidate>`
825-
by creating a new change stream. For the resume token, use the ``_id`` value of
826-
the :ref:`change stream event document <change-stream-output>`. See
827-
:ref:`change-stream-resume-token` for more information on the resume token.
830+
by creating a new change stream.
831+
832+
See :ref:`change-stream-resume-token` for more information on the resume token.
828833

829834
.. important::
830835

@@ -837,22 +842,133 @@ the :ref:`change stream event document <change-stream-output>`. See
837842
Resume Tokens
838843
~~~~~~~~~~~~~
839844

840-
The ``_id`` value of a :ref:`change stream event document
841-
<change-stream-output>` acts as the resume token:
845+
The resume token is available from multiple sources:
846+
847+
.. list-table::
848+
:header-rows: 1
849+
:stub-columns: 1
850+
:widths: 20 80
851+
852+
* - Source
853+
- Description
854+
855+
* - :ref:`Change Events <change-event-resume-token>`
856+
- Each change event notification includes a resume token
857+
on the ``_id`` field.
858+
859+
* - :ref:`Aggregation <aggregate-resume-token>`
860+
- The :pipeline:`$changeStream` aggregation stage includes
861+
a resume token on the ``cursor.postBatchResumeToken`` field.
862+
863+
This field only appears when using the :dbcommand:`aggregate`
864+
command.
865+
866+
* - :ref:`Get More <getMore-resume-token>`
867+
- The :dbcommand:`getMore` command includes a resume token on the
868+
``cursor.postBatchResumeToken`` field.
869+
870+
.. versionchanged:: 4.2
871+
872+
.. include:: /includes/extracts/4.2-changes-change-stream-modification-error.rst
873+
874+
.. _change-event-resume-token:
875+
876+
Resume Tokens from Change Events
877+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
878+
879+
Change event notifications include a resume token on the ``_id`` field:
880+
881+
.. code-block:: json
882+
:copyable: false
883+
:emphasize-lines: 2-4
842884

843-
.. code-block:: none
844885

845886
{
846-
"_data" : <BinData|hex string>
887+
"_id": {
888+
"_data": "82635019A0000000012B042C0100296E5A1004AB1154ACACD849A48C61756D70D3B21F463C6F7065726174696F6E54797065003C696E736572740046646F63756D656E744B65790046645F69640064635019A078BE67426D7CF4D2000004"
889+
},
890+
"operationType": "insert",
891+
"clusterTime": Timestamp({ "t": 1666193824, "i": 1 }),
892+
"collectionUUID": new UUID("ab1154ac-acd8-49a4-8c61-756d70d3b21f"),
893+
"fullDocument": {
894+
"_id": ObjectId("635019a078be67426d7cf4d2"'),
895+
"name": "Giovanni Verga"
896+
},
897+
"ns": {
898+
"db": "test",
899+
"coll": "names"
900+
},
901+
"documentKey": {
902+
"_id": ObjectId("635019a078be67426d7cf4d2")
903+
}
847904
}
848905

849-
.. include:: /includes/extracts/changestream-resume-token-versions-4.2-greater.rst
850906

851-
.. include:: /includes/extracts/changestream-resume-token-hex-change.rst
907+
.. _aggregate-resume-token:
852908

853-
.. tip::
909+
Resume Tokens from ``aggregate``
910+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
911+
912+
When using the :dbcommand:`aggregate` command, the :pipeline:`$changeStream`
913+
aggregation stage includes a resume token on the
914+
``cursor.postBatchResumeToken`` field:
915+
916+
.. code-block:: json
917+
:copyable: false
918+
:emphasize-lines: 4-6
919+
920+
{
921+
"cursor": {
922+
"firstBatch": [],
923+
"postBatchResumeToken": {
924+
"_data": "8263515EAC000000022B0429296E1404"
925+
},
926+
"id": Long("4309380460777152828"),
927+
"ns": "test.names"
928+
},
929+
"ok": 1,
930+
"$clusterTime": {
931+
"clusterTime": Timestamp({ "t": 1666277036, "i": 1 }),
932+
"signature": {
933+
"hash": Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
934+
"keyId": Long("0")
935+
}
936+
},
937+
"operationTime": Timestamp({ "t": 1666277036, "i": 1 })
938+
}
939+
940+
.. _getMore-resume-token:
941+
942+
Resume Tokens from ``getMore``
943+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
944+
945+
The :dbcommand:`getMore` command also includes a resume token on the
946+
``cursor.postBatchResumeToken`` field:
947+
948+
.. code-block:: json
949+
:copyable: false
950+
:emphasize-lines: 4-6
951+
952+
{
953+
"cursor": {
954+
"nextBatch": [],
955+
"postBatchResumeToken": {
956+
"_data": "8263515979000000022B0429296E1404"
957+
},
958+
"id": Long("7049907285270685005"),
959+
"ns": "test.names"
960+
},
961+
"ok": 1,
962+
"$clusterTime": {
963+
"clusterTime": Timestamp( { "t": 1666275705, "i": 1 } ),
964+
"signature": {
965+
"hash": Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
966+
"keyId": Long("0")
967+
}
968+
},
969+
"operationTime": Timestamp({ "t": 1666275705, "i": 1 })
970+
}
854971

855-
.. include:: /includes/extracts/4.2-changes-change-stream-modification-error.rst
856972

857973
Use Cases
858974
---------

source/reference/command/getMore.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ For example, a document similar to the one below may be returned when
114114
"_id" : ObjectId("5e8e501e1a32d227f9085857"),
115115
"zipcode" : "220000"
116116
}
117-
]
117+
],
118+
"postBatchResumeToken": "< Resume Token >"
118119
},
119120
"ok" : 1,
120121
"operationTime" : Timestamp(1586385239, 2),
@@ -139,6 +140,10 @@ For example, a document similar to the one below may be returned when
139140
- Contains the cursor information, including the
140141
cursor id as well as the ``nextBatch`` of documents.
141142

143+
The ``postBatchResumeToken`` field can be used with the
144+
:pipeline:`$changeStream` pipeline to start or resume
145+
a change stream from this point.
146+
142147
* - ``"ok"``
143148

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

0 commit comments

Comments
 (0)