@@ -94,6 +94,11 @@ Description
94
94
- document
95
95
- .. include:: /includes/change-stream/updateDescription
96
96
97
+ * - | ``updateDescription.``
98
+ | ``disambiguatedPaths``
99
+ - document
100
+ - .. include:: /includes/change-stream/ud-disambiguatedPaths
101
+
97
102
* - | ``updateDescription.``
98
103
| ``removedFields``
99
104
- array
@@ -138,6 +143,83 @@ Document Pre- and Post-Images
138
143
139
144
.. include:: /includes/change-stream-pre-and-post-images-additional-information.rst
140
145
146
+ Path Disambiguation
147
+ ^^^^^^^^^^^^^^^^^^^
148
+
149
+ .. versionadded:: 6.1
150
+
151
+ The ``updateDescription`` field notes changes made to specific fields in
152
+ documents by an operation. These field descriptors use dots (``.``) as
153
+ path separators and numbers as array indexes, which leads to some
154
+ ambiguity when it contains field names that use dots or numbers.
155
+
156
+ When an ``update`` event reports changes involving ambiguous fields,
157
+ the ``disambiguatedPaths`` document provides the path key with an array
158
+ listing each path component.
159
+
160
+ .. note::
161
+
162
+ The ``disambiguatedPaths`` field is only available on change streams
163
+ started with the :ref:`showExpandedEvents
164
+ <change-streams-expanded-events>` option
165
+
166
+ For example, consider a document that lists people and the towns in which they
167
+ live:
168
+
169
+ .. code-block:: json
170
+
171
+ {
172
+ "name": "Anthony Trollope",
173
+ "home.town": "Oxford",
174
+ "residences": [
175
+ {"0": "Oxford"},
176
+ {"1": "Sunbury"}
177
+ ]
178
+ }
179
+
180
+ * When an update modifies the ``home.town`` field from ``Oxford`` to
181
+ ``London``, it produces an update description that looks like this:
182
+
183
+ .. code-block:: json
184
+
185
+ "updateDescription": {
186
+ "updatedFields": {
187
+ "home.town": "London"
188
+ },
189
+ "disambiguatedPaths": {
190
+ "home.town": [ "home.town" ]
191
+ }
192
+ }
193
+
194
+ Because the field ``home.town`` contains a period, the ``disambiguatedPaths``
195
+ field shows an array with one value, to indicate that ``town`` is not a
196
+ sub-field of ``home``.
197
+
198
+ * When an update modifies a value in the ``residences`` array to make the same
199
+ change, it produces an update description that looks like this:
200
+
201
+ .. code-block:: json
202
+
203
+ "updateDescription": {
204
+ "updatedFields": {
205
+ "residences.0.0": "London"
206
+ },
207
+ "disambiguatedPaths": { "residences.0.0": [ "residences", 0, "0" ] }
208
+ }
209
+
210
+ The disambiguated paths include an integer ``0`` to indicate the array index
211
+ and the string ``"0"`` to indicate the field name within the nested document.
212
+
213
+ There are two cases where ``disambiguatedPath`` does **not** include a
214
+ numeric field:
215
+
216
+ * When the first field in the path is a numeric string (i.e. ``0.name``).
217
+ This is not ambiguous since the first field cannot be an array index.
218
+
219
+
220
+ * When the numeric string field has leading zeroes (i.e., ``0001``).
221
+ This is not ambiguous since an integer cannot have leading zeroes.
222
+
141
223
142
224
Example
143
225
-------
@@ -197,7 +279,8 @@ opened with the ``fullDocument : updateLookup`` option:
197
279
"truncatedArrays": [ {
198
280
"field" : "vacation_time",
199
281
"newSize" : 36
200
- } ]
282
+ } ],
283
+ "disambiguatedPaths": { }
201
284
},
202
285
"fullDocument": {
203
286
"_id": ObjectId("58a4eb4a30c75625e00d2820"),
0 commit comments