Skip to content

Commit d3db939

Browse files
jason-price-mongodbjeff-allen-mongo
jason-price-mongodb
authored andcommitted
DOCS-14609 SBE order projection fields
1 parent e5c2d18 commit d3db939

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

source/core/document.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,37 @@ Document Size Limit
200200
Document Field Order
201201
~~~~~~~~~~~~~~~~~~~~
202202

203+
Unlike JavaScript objects, the fields in a BSON document are ordered.
204+
205+
Field Order in Queries
206+
``````````````````````
207+
208+
For queries, the field order behavior is as follows:
209+
210+
- When comparing documents, field ordering is significant. For
211+
example, when comparing documents with fields ``a`` and ``b`` in a
212+
query:
213+
214+
- ``{a: 1, b: 1}`` is equal to ``{a: 1, b: 1}``
215+
216+
- ``{a: 1, b: 1}`` is not equal to ``{b: 1, a: 1}``
217+
218+
- For efficient query execution, the query engine may reorder fields
219+
during query processing. Among other cases, reordering fields may
220+
occur when processing these projection operators:
221+
:pipeline:`$project`, :pipeline:`$addFields`, :pipeline:`$set`, and
222+
:pipeline:`$unset`.
223+
224+
- Field reordering may occur in intermediate results as well as the
225+
final results returned by a query.
226+
227+
- Because some operations may reorder fields, you should not rely on
228+
specific field ordering in the results returned by a query that
229+
uses the projection operators listed earlier.
230+
231+
Field Order in Write Operations
232+
```````````````````````````````
233+
203234
.. include:: /includes/fact-update-field-order.rst
204235
:start-after: order-of-document-fields
205236

source/includes/fact-update-field-order.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. order-of-document-fields
22
3-
MongoDB preserves the order of the document fields following write
4-
operations *except* for the following cases:
3+
For write operations, MongoDB preserves the order of the document fields
4+
*except* for the following cases:
55

66
- The ``_id`` field is always the first field in the document.
77

0 commit comments

Comments
 (0)