Skip to content

Commit edc55e1

Browse files
authored
DOCS-15156 change stream index events (#1051)
* DOCS-15156 Adds index events * DOCS-15156 Adds index events * DOCS-15156 Adds index events * DOCS-15156 Adds index events * DOCS-15156 Fixes per Jason Price * DOCS-15156 Fixes per Jason * DOCS-15156 Fixes per Jason Price * DOCS-15156 Fixes per Jason Price * DOCS-15156 Fixes per Jason Price * DOCS-15156 Fixes per Kyle Suarez * DOCS-15156 Fixes per Kyle Suarez
1 parent c5319f3 commit edc55e1

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

source/changeStreams.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,31 @@ Change Streams with Document Pre- and Post-Images
10641064
For complete examples with the change stream output, see
10651065
:ref:`db.collection.watch-change-streams-pre-and-post-images-example`.
10661066

1067+
.. _change-streams-expanded-events:
1068+
1069+
Expanded Events
1070+
---------------
1071+
1072+
.. versionadded:: 6.0
1073+
1074+
Starting in MongoDB 6.0, change streams support change notifications for DDL
1075+
events, like the :ref:`createIndexes <change-event-createIndexes>` and
1076+
:ref:`dropIndexes <change-event-dropIndexes>`. To include expanded
1077+
events in a change stream, create the change stream cursor using the
1078+
``showExpandedEvents`` option.
1079+
1080+
For example:
1081+
1082+
.. code-block:: javascript
1083+
1084+
let cur = db.names.aggregate( [
1085+
$changeStream: {
1086+
showExpandedEvents: true
1087+
}
1088+
] )
1089+
1090+
cur.next()
1091+
10671092
.. toctree::
10681093
:titlesonly:
10691094
:hidden:

source/reference/change-events.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ stream response document can have.
4444
...
4545
]
4646
},
47+
"operationDescription": {
48+
"indexes": [
49+
<document>
50+
]
51+
},
52+
"collectionUUID": <uuid>,
53+
"wallTime": <isodate>,
4754
"clusterTime" : <Timestamp>,
4855
"txnNumber" : <NumberLong>,
4956
"lsid" : {
@@ -100,6 +107,8 @@ following table describes each field in the change stream response document:
100107
- ``rename``
101108
- ``dropDatabase``
102109
- ``invalidate``
110+
- ``createIndexes``
111+
- ``dropIndexes``
103112

104113
* - ``fullDocument``
105114
- document
@@ -224,6 +233,36 @@ following table describes each field in the change stream response document:
224233
| ``newSize``
225234
- integer
226235
- The number of elements in the truncated array.
236+
* - ``operationDescription``
237+
- document
238+
- A document describing the operation performed.
239+
240+
This document and its fields only appears if the ``operationType`` value
241+
is an expanded event.
242+
243+
.. versionadded:: 6.0
244+
245+
* - ``operationDescription.indexes``
246+
- array
247+
- An array of documents listing the indexes that were created or dropped
248+
by the operation.
249+
250+
This field only appears when the ``operationType`` value is ``createIndexes``
251+
or ``dropIndexes``.
252+
253+
.. versionadded:: 6.0
254+
255+
* - ``wallTime``
256+
- ISODate
257+
- ISO date from the oplog entry associated with the event.
258+
259+
.. versionadded:: 6.0
260+
261+
* - ``collectionUUID``
262+
- UUID
263+
- UUID identifying the collection.
264+
265+
.. versionadded:: 6.0
227266

228267
* - ``clusterTime``
229268

@@ -555,3 +594,65 @@ watched database leads to an
555594

556595
.. include:: /includes/extracts/changestream-invalid-events.rst
557596

597+
598+
.. _change-event-createIndexes:
599+
600+
``createIndexes`` Event
601+
-----------------------
602+
603+
.. versionadded:: 6.0
604+
605+
A ``createIndexes`` event occurs when an index is created on the collection and
606+
the change stream has the ``showExpandedEvents`` option set to ``true``.
607+
608+
The following example shows a ``createIndexes`` event:
609+
610+
.. code-block:: text
611+
612+
{
613+
_id: { <ResumeToken> },
614+
operationType: 'createIndexes',
615+
clusterTime: Timestamp({ t: 1651257835, i: 1 }),
616+
collectionUUID: UUID("06bced37-7cc8-4267-96aa-a58a422153d8"),
617+
wallTime: ISODate("2022-04-29T18:43:55.160Z"),
618+
ns: {
619+
db: 'test',
620+
coll: 'authors'
621+
},
622+
operationDescription: {
623+
indexes: [
624+
{ v: 2, key: { name: 1 }, name: 'name_1' }
625+
]
626+
}
627+
}
628+
629+
630+
.. _change-event-dropIndexes:
631+
632+
``dropIndexes`` Event
633+
---------------------
634+
635+
.. versionadded:: 6.0
636+
637+
A ``dropIndexes`` event occurs when an index is dropped from the collection and
638+
the change stream has the ``showExpandedEvents`` option set to ``true``.
639+
640+
The following example shows a ``dropIndexes`` event:
641+
642+
.. code-block:: text
643+
644+
{
645+
_id: { <ResumeToken> },
646+
operationType: 'dropIndexes',
647+
clusterTime: <Timestamp>
648+
collectionUUID: <uuid>,
649+
wallTime: <isodate>,
650+
ns: {
651+
db: 'test',
652+
coll: 'authors' },
653+
operationDescription: {
654+
indexes: [
655+
{ v: 2, key: { name: 1 }, name: 'name_1' }
656+
]
657+
}
658+
}

source/release-notes/6.0.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,15 @@ Starting in MongoDB 6.0, you can use :ref:`change streams
604604
after changes (the document pre- and post-images). For examples, see
605605
:ref:`db.collection.watch-change-streams-pre-and-post-images-example`.
606606

607+
Change Stream Expanded Events
608+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
609+
610+
Starting in MongoDB 6.0, change streams can be configured to show additional
611+
change events for DDL operations, like index creation and collection drop.
612+
613+
For more information, see :ref:`Expanded Events <change-streams-expanded-events>`.
614+
615+
607616
Exclude Embedded Fields in ``serverStatus`` Output
608617
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
609618

0 commit comments

Comments
 (0)