Skip to content

Commit 293425d

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

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

source/core/document.txt

+31
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,37 @@ 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 documents with fields ``a`` and ``b`` in a
211+
query:
212+
213+
- ``{a: 1, b: 1}`` is equal to ``{a: 1, b: 1}``
214+
215+
- ``{a: 1, b: 1}`` is not equal to ``{b: 1, a: 1}``
216+
217+
- For efficient query execution, the query engine may reorder fields
218+
during query processing. Among other cases, reordering fields may
219+
occur when processing these projection operators:
220+
:pipeline:`$project`, :pipeline:`$addFields`, :pipeline:`$set`, and
221+
:pipeline:`$unset`.
222+
223+
- Field reordering may occur in intermediate results as well as the
224+
final results returned by a query.
225+
226+
- Because some operations may reorder fields, you should not rely on
227+
specific field ordering in the results returned by a query that
228+
uses the projection operators listed earlier.
229+
230+
Field Order in Write Operations
231+
```````````````````````````````
232+
202233
.. include:: /includes/fact-update-field-order.rst
203234
:start-after: order-of-document-fields
204235

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)