@@ -30,6 +30,10 @@ stream response document can have.
30
30
"db" : "<database>",
31
31
"coll" : "<collection"
32
32
},
33
+ "to" : {
34
+ "db" : "<database>",
35
+ "coll" : "<collection"
36
+ },
33
37
"documentKey" : { "_id" : <ObjectId> },
34
38
"updateDescription" : {
35
39
"updatedFields" : { <document> },
@@ -73,11 +77,15 @@ following table describes each field in the change stream response document:
73
77
- ``delete``
74
78
- ``replace``
75
79
- ``update``
80
+ - ``drop``
81
+ - ``rename``
82
+ - ``dropDatabase``
76
83
- ``invalidate``
77
84
78
85
* - ``fullDocument``
79
86
- 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).
81
89
82
90
For ``insert`` and ``replace`` operations, this represents the new
83
91
document created by the operation.
@@ -95,8 +103,7 @@ following table describes each field in the change stream response document:
95
103
96
104
* - ``ns``
97
105
- 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.
100
107
101
108
* - ``ns.db``
102
109
- string
@@ -106,9 +113,26 @@ following table describes each field in the change stream response document:
106
113
- string
107
114
- The name of the collection.
108
115
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
+
109
132
* - ``documentKey``
110
133
- 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).
112
136
For sharded collections, also displays the full shard key for the
113
137
document. The ``_id`` field is not repeated if it is already a
114
138
part of the shard key.
@@ -320,6 +344,89 @@ The following example illustrates a ``delete`` event:
320
344
The ``fullDocument`` document is omitted as the document no longer exists at the
321
345
time the change stream cursor sends the ``delete`` event to the client.
322
346
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.
323
430
324
431
.. _change-event-invalidate:
325
432
@@ -336,19 +443,17 @@ The following example illustrates an ``invalidate`` event:
336
443
clusterTime: <Timestamp>
337
444
}
338
445
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>`.
352
457
353
458
``invalidate`` events close the change stream cursor.
354
459
0 commit comments