Skip to content

Commit 7a29ffb

Browse files
Isabella Siukay-kim
authored andcommitted
DOCS-11829 add change stream notification for drop, rename, and dropDatabase
1 parent 3612ce6 commit 7a29ffb

File tree

1 file changed

+122
-17
lines changed

1 file changed

+122
-17
lines changed

source/reference/change-events.txt

Lines changed: 122 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ stream response document can have.
3030
"db" : "<database>",
3131
"coll" : "<collection"
3232
},
33+
"to" : {
34+
"db" : "<database>",
35+
"coll" : "<collection"
36+
},
3337
"documentKey" : { "_id" : <ObjectId> },
3438
"updateDescription" : {
3539
"updatedFields" : { <document> },
@@ -73,11 +77,15 @@ following table describes each field in the change stream response document:
7377
- ``delete``
7478
- ``replace``
7579
- ``update``
80+
- ``drop``
81+
- ``rename``
82+
- ``dropDatabase``
7683
- ``invalidate``
7784

7885
* - ``fullDocument``
7986
- document
80-
- The document created or modified by the operation.
87+
- The document created or modified by the ``insert``, ``replace``,
88+
``delete``, ``update`` operations (i.e. CRUD operations).
8189

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

96104
* - ``ns``
97105
- document
98-
- The namespace of the database and collection the change stream is open
99-
against.
106+
- The namespace (database and or collection) affected by the event.
100107

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

116+
For ``dropDatabase`` operations, this field is omitted.
117+
118+
* - ``to``
119+
- document
120+
- When ``operationType : rename``, this document displays the new name for
121+
the ``ns`` collection. This document is omitted for all other
122+
values of ``operationType``.
123+
124+
* - ``to.db``
125+
- string
126+
- The new name of the database.
127+
128+
* - ``to.coll``
129+
- string
130+
- The new name of the collection.
131+
109132
* - ``documentKey``
110133
- document
111-
- The ObjectID of the document created or modified by the operation.
134+
- The ObjectID of the document created or modified by the ``insert``,
135+
``replace``, ``delete``, ``update`` operations (i.e. CRUD operations).
112136
For sharded collections, also displays the full shard key for the
113137
document. The ``_id`` field is not repeated if it is already a
114138
part of the shard key.
@@ -320,6 +344,89 @@ The following example illustrates a ``delete`` event:
320344
The ``fullDocument`` document is omitted as the document no longer exists at the
321345
time the change stream cursor sends the ``delete`` event to the client.
322346

347+
.. _change-streams-drop-event:
348+
349+
``drop`` Event
350+
----------------
351+
352+
.. versionadded:: 4.0.1
353+
354+
A ``drop`` event occurs when a collection is dropped from a database. The
355+
following example illustrates a ``drop`` event:
356+
357+
.. code-block:: none
358+
359+
{
360+
_id: { < Resume Token > },
361+
operationType: 'drop',
362+
clusterTime: <Timestamp>,
363+
ns: {
364+
db: 'engineering',
365+
coll: 'users'
366+
}
367+
}
368+
369+
A ``drop`` event leads to an :ref:`invalidate event <change-event-invalidate>`
370+
for change streams opened against its ``ns`` collection.
371+
372+
.. _change-streams-rename-event:
373+
374+
``rename`` Event
375+
----------------
376+
377+
.. versionadded:: 4.0.1
378+
379+
A ``rename`` event occurs when a collection is renamed. The following example
380+
illustrates a ``rename`` event:
381+
382+
.. code-block:: none
383+
384+
{
385+
_id: { < Resume Token > },
386+
operationType: 'rename',
387+
clusterTime: <Timestamp>,
388+
ns: {
389+
db: 'engineering',
390+
coll: 'users'
391+
},
392+
to: {
393+
db: 'engineering',
394+
coll: 'people'
395+
}
396+
}
397+
398+
A ``rename`` event leads to an
399+
:ref:`invalidate event <change-event-invalidate>` for change streams opened
400+
against its ``ns`` collection or ``to`` collection.
401+
402+
.. _change-streams-dropDatabase-event:
403+
404+
``dropDatabase`` Event
405+
----------------------
406+
407+
.. versionadded:: 4.0.1
408+
409+
A ``dropDatabase`` event occurs when a database is dropped. The following
410+
example illustrates a ``dropDatabase`` event:
411+
412+
.. code-block:: none
413+
414+
{
415+
_id: { < Resume Token > },
416+
operationType: 'dropDatabase',
417+
clusterTime: <Timestamp>,
418+
ns: {
419+
db: 'engineering'
420+
}
421+
}
422+
423+
A :dbcommand:`dropDatabase` command generates a
424+
:ref:`drop event <change-streams-drop-event>` for each collection in
425+
the database before generating a ``dropDatabase`` event for the database.
426+
427+
A ``dropDatabase`` event leads to an
428+
:ref:`invalidate event <change-event-invalidate>` for change streams opened
429+
against its ``ns.db`` database.
323430

324431
.. _change-event-invalidate:
325432

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

339-
For change stream opened against a collection,
340-
``invalidate`` events occur after a :dbcommand:`dropDatabase`,
341-
:dbcommand:`drop`, or :dbcommand:`renameCollection` command that
342-
affects the watched collection.
343-
344-
For change stream opened against a database, ``invalidate`` events
345-
occur after a :dbcommand:`dropDatabase`, :dbcommand:`drop`, or
346-
:dbcommand:`renameCollection` command that affects the watched database.
347-
348-
For change stream opened against the deployment, ``invalidate`` events
349-
occur after a :dbcommand:`dropDatabase`, :dbcommand:`drop`, or
350-
:dbcommand:`renameCollection` command occurs in the deployment.
351-
446+
For change streams opened up against a collection, a
447+
:ref:`drop event <change-streams-drop-event>`,
448+
:ref:`rename event <change-streams-rename-event>`, or
449+
:ref:`dropDatabase event <change-streams-dropDatabase-event>` that affects the
450+
watched collection leads to an
451+
:ref:`invalidate event <change-event-invalidate>`.
452+
453+
For change streams opened up against a database, a
454+
:ref:`dropDatabase event <change-streams-dropDatabase-event>` that affects the
455+
watched database leads to an
456+
:ref:`invalidate event <change-event-invalidate>`.
352457

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

0 commit comments

Comments
 (0)