Skip to content

DOCS-11829 add change stream notification for drop, rename, and dropD… #3450

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
Oct 12, 2018
Merged
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
139 changes: 122 additions & 17 deletions source/reference/change-events.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ stream response document can have.
"db" : "<database>",
"coll" : "<collection"
},
"to" : {
"db" : "<database>",
"coll" : "<collection"
},
"documentKey" : { "_id" : <ObjectId> },
"updateDescription" : {
"updatedFields" : { <document> },
Expand Down Expand Up @@ -73,11 +77,15 @@ following table describes each field in the change stream response document:
- ``delete``
- ``replace``
- ``update``
- ``drop``
- ``rename``
- ``dropDatabase``
- ``invalidate``

* - ``fullDocument``
- document
- The document created or modified by the operation.
- The document created or modified by the ``insert``, ``replace``,
``delete``, ``update`` operations (i.e. CRUD operations).

For ``insert`` and ``replace`` operations, this represents the new
document created by the operation.
Expand All @@ -95,8 +103,7 @@ following table describes each field in the change stream response document:

* - ``ns``
- document
- The namespace of the database and collection the change stream is open
against.
- The namespace (database and or collection) affected by the event.

* - ``ns.db``
- string
Expand All @@ -106,9 +113,26 @@ following table describes each field in the change stream response document:
- string
- The name of the collection.

For ``dropDatabase`` operations, this field is omitted.

* - ``to``
- document
- When ``operationType : rename``, this document displays the new name for
the ``ns`` collection. This document is omitted for all other
values of ``operationType``.

* - ``to.db``
- string
- The new name of the database.

* - ``to.coll``
- string
- The new name of the collection.

* - ``documentKey``
- document
- The ObjectID of the document created or modified by the operation.
- The ObjectID of the document created or modified by the ``insert``,
``replace``, ``delete``, ``update`` operations (i.e. CRUD operations).
For sharded collections, also displays the full shard key for the
document. The ``_id`` field is not repeated if it is already a
part of the shard key.
Expand Down Expand Up @@ -320,6 +344,89 @@ 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-streams-drop-event:

``drop`` Event
----------------

.. versionadded:: 4.0.1

A ``drop`` event occurs when a collection is dropped from a database. The
following example illustrates a ``drop`` event:

.. code-block:: none

{
_id: { < Resume Token > },
operationType: 'drop',
clusterTime: <Timestamp>,
ns: {
db: 'engineering',
coll: 'users'
}
}

A ``drop`` event leads to an :ref:`invalidate event <change-event-invalidate>`
for change streams opened against its ``ns`` collection.

.. _change-streams-rename-event:

``rename`` Event
----------------

.. versionadded:: 4.0.1

A ``rename`` event occurs when a collection is renamed. The following example
illustrates a ``rename`` event:

.. code-block:: none

{
_id: { < Resume Token > },
operationType: 'rename',
clusterTime: <Timestamp>,
ns: {
db: 'engineering',
coll: 'users'
},
to: {
db: 'engineering',
coll: 'people'
}
}

A ``rename`` event leads to an
:ref:`invalidate event <change-event-invalidate>` for change streams opened
against its ``ns`` collection or ``to`` collection.

.. _change-streams-dropDatabase-event:

``dropDatabase`` Event
----------------------

.. versionadded:: 4.0.1

A ``dropDatabase`` event occurs when a database is dropped. The following
example illustrates a ``dropDatabase`` event:

.. code-block:: none

{
_id: { < Resume Token > },
operationType: 'dropDatabase',
clusterTime: <Timestamp>,
ns: {
db: 'engineering'
}
}

A :dbcommand:`dropDatabase` command generates a
:ref:`drop event <change-streams-drop-event>` for each collection in
the database before generating a ``dropDatabase`` event for the database.

A ``dropDatabase`` event leads to an
:ref:`invalidate event <change-event-invalidate>` for change streams opened
against its ``ns.db`` database.

.. _change-event-invalidate:

Expand All @@ -336,19 +443,17 @@ The following example illustrates an ``invalidate`` event:
clusterTime: <Timestamp>
}

For change stream opened against a collection,
``invalidate`` events occur after a :dbcommand:`dropDatabase`,
:dbcommand:`drop`, or :dbcommand:`renameCollection` command that
affects the watched collection.

For change stream opened against a database, ``invalidate`` events
occur after a :dbcommand:`dropDatabase`, :dbcommand:`drop`, or
:dbcommand:`renameCollection` command that affects the watched database.

For change stream opened against the deployment, ``invalidate`` events
occur after a :dbcommand:`dropDatabase`, :dbcommand:`drop`, or
:dbcommand:`renameCollection` command occurs in the deployment.

For change streams opened up against a collection, a
:ref:`drop event <change-streams-drop-event>`,
:ref:`rename event <change-streams-rename-event>`, or
:ref:`dropDatabase event <change-streams-dropDatabase-event>` that affects the
watched collection leads to an
:ref:`invalidate event <change-event-invalidate>`.

For change streams opened up against a database, a
:ref:`dropDatabase event <change-streams-dropDatabase-event>` that affects the
watched database leads to an
:ref:`invalidate event <change-event-invalidate>`.

``invalidate`` events close the change stream cursor.

Expand Down