Skip to content

Commit 4c1a77e

Browse files
author
jason-price-mongodb
committed
DOCS-14609 SBE order projection fields
1 parent 15d1e4b commit 4c1a77e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

source/core/document.txt

+30
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,36 @@ Document Size Limit
199199
Document Field Order
200200
~~~~~~~~~~~~~~~~~~~~
201201

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

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

+2-2
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)