Skip to content

Commit a85343e

Browse files
authored
DOCS-15377 disambiguatedPaths for updateDescription (#1991)
* DOCS-15377 Adds disambiguatedPath * DOCS-15377 Adds behavioral description * DOCS-15377 Adds behavioral description * DOCS-15377 Fixes build issue * DOCS-15377 Fixes text * DOCS-15377 Fixes text * DOCS-15377 Fixes text * DOCS-15377 Text fix * DOCS-15377 Fixes text * DOCS-15377 Fixes per Jocelyn * DOCS-15377 Fixes per Jocelyn * DOCS-15377 Fixes per Arun * DOCS-15377 Fixes * DOCS-15377 Fixes per Arun * DOCS-15377 Fixes per Arun * DOCS-15377 Fixes per Arun * DOCS-15377 Fixes per Arun * DOCS-15377 Fixes per Arun * DOCS-15377 Fixes per Arun
1 parent b0fc0ed commit a85343e

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _|idref|-ud-disambiguatedPaths:
2+
3+
A document that provides clarification of ambiguous
4+
field descriptors in ``updateDescription``.
5+
6+
When the ``update`` change event describes changes on a field where
7+
the path contains a period (``.``) or where the path includes
8+
a non-array numeric subfield, the ``disambiguatedPath`` field
9+
provides a document with an array that
10+
lists each entry in the path to the modified field.
11+
12+
Requires that you set the :ref:`showExpandedEvents
13+
<change-streams-expanded-events>` option to ``true``.
14+
15+
.. versionadded:: 6.1
16+
17+

source/reference/change-events/update.txt

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ Description
9494
- document
9595
- .. include:: /includes/change-stream/updateDescription
9696

97+
* - | ``updateDescription.``
98+
| ``disambiguatedPaths``
99+
- document
100+
- .. include:: /includes/change-stream/ud-disambiguatedPaths
101+
97102
* - | ``updateDescription.``
98103
| ``removedFields``
99104
- array
@@ -138,6 +143,83 @@ Document Pre- and Post-Images
138143

139144
.. include:: /includes/change-stream-pre-and-post-images-additional-information.rst
140145

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+
141223

142224
Example
143225
-------
@@ -197,7 +279,8 @@ opened with the ``fullDocument : updateLookup`` option:
197279
"truncatedArrays": [ {
198280
"field" : "vacation_time",
199281
"newSize" : 36
200-
} ]
282+
} ],
283+
"disambiguatedPaths": { }
201284
},
202285
"fullDocument": {
203286
"_id": ObjectId("58a4eb4a30c75625e00d2820"),

0 commit comments

Comments
 (0)