Skip to content

DOCS-10668: Change stream invalidate events #3142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Change Streams Production Recommendations
:depth: 1
:class: singlecol

If you drop a collection with change streams opened against it, the change
stream cursors close when they advance to that point in the oplog. Change
stream cursors with the ``fullDocument : updateLookup`` option may return
``null`` for the lookup document.
If you drop or rename a collection or database with change streams
opened against it, the change stream cursors close when they advance to
that point in the oplog. Change stream cursors with the ``fullDocument :
updateLookup`` option may return ``null`` for the lookup document.

Attempting to resume a change stream against a dropped collection results in
an error. Any data changes that occurred on the collection between the last
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. note::
:ref:`Invalidated <change-event-invalidate>` change streams cannot be
resumed. Attempting to resume a change stream against a dropped or
renamed collection results in an error.
81 changes: 53 additions & 28 deletions source/reference/change-events.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ The following example illustrates an ``insert`` event:

{
_id: { < Resume Token > },
operationType: insert,
operationType: 'insert',
ns: {
db: engineering,
coll: users
db: 'engineering',
coll: 'users'
},
documentKey: {
userName: alice123,
userName: 'alice123',
_id: ObjectId("599af247bb69cd89961c986d")
},
fullDocument: {
_id: ObjectId("599af247bb69cd89961c986d"),
userName: alice123,
name: Alice
userName: 'alice123',
name: 'Alice'
}
}

Expand All @@ -164,19 +164,19 @@ The following example illustrates an ``update`` event:

{
_id: { < Resume Token > },
operationType: update,
operationType: 'update',
ns: {
db: engineering,
coll: users
db: 'engineering',
coll: 'users'
},
documentKey: {
_id: ObjectId("58a4eb4a30c75625e00d2820")
},
updateDescription: {
updatedFields: {
email: [email protected]
email: '[email protected]'
},
removedFields: [phoneNumber]
removedFields: ['phoneNumber']
}
}

Expand All @@ -187,26 +187,26 @@ opened with the ``fullDocument : updateLookup`` option:

{
_id: { < Resume Token > },
operationType: update,
operationType: 'update',
ns: {
db: engineering,
coll: users
db: 'engineering',
coll: 'users'
},
documentKey: {
_id: ObjectId("58a4eb4a30c75625e00d2820")
},
updateDescription: {
updatedFields: {
email: [email protected]
email: '[email protected]'
},
removedFields: [phoneNumber]
removedFields: ['phoneNumber']
},
fullDocument: {
_id: ObjectId("58a4eb4a30c75625e00d2820"),
name: Alice,
userName: alice123,
email: [email protected],
team: replication
name: 'Alice',
userName: 'alice123',
email: '[email protected]',
team: 'replication'
}
}

Expand All @@ -225,18 +225,18 @@ The following example illustrates a ``replace`` event:

{
_id: { < Resume Token > },
operationType: replace,
operationType: 'replace',
ns: {
db: engineering,
coll: users
db: 'engineering',
coll: 'users'
},
documentKey: {
_id: ObjectId("599af247bb69cd89961c986d")
},
fullDocument: {
_id: ObjectId("599af247bb69cd89961c986d"),
userName: alice123,
name: Alice
userName: 'alice123',
name: 'Alice'
}
}

Expand All @@ -263,10 +263,10 @@ The following example illustrates a ``delete`` event:
"$oid":"599af247bb69cd89961c986d"
}
},
operationType: delete,
operationType: 'delete',
ns: {
db: engineers’,
coll: users
db: 'engineers',
coll: 'users'
},
documentKey: {
_id: ObjectId("599af247bb69cd89961c986d")
Expand All @@ -275,3 +275,28 @@ The following example illustrates a ``delete`` event:

The ``fullDocument`` document is omitted as the document no longer exists at the
time the change stream cursor sends the ``delete`` event to the client.


.. _change-event-invalidate:

``invalidate`` Event
--------------------

The following example illustrates an ``invalidate`` event:

.. code-block:: none

{
_id: { < Resume Token > },
operationType: 'invalidate'
}

All fields except for ``_id`` and ``operationType`` are omitted.

``invalidate`` events occur after a :dbcommand:`dropDatabase`,
:dbcommand:`drop`, or :dbcommand:`renameCollection` command that
affects the watched collection. ``invalidate`` events close the change
stream cursor and signal that any locally cached data is out
of sync with the server.

.. include:: /includes/fact-cannot-resume-invalidated-change-stream.rst
2 changes: 2 additions & 0 deletions source/tutorial/change-streams-example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ notification after a specific notification.
As long as that operation has not rolled off the :term:`oplog`, the
change stream can successfully resume notifications.

.. include:: /includes/fact-cannot-resume-invalidated-change-stream.rst

See :ref:`change-stream-output` for more information on the change stream
response document format.