Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-14609 SBE order projection fields #5875

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions source/core/document.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,37 @@ Document Size Limit
Document Field Order
~~~~~~~~~~~~~~~~~~~~

Unlike JavaScript objects, the fields in a BSON document are ordered.

Field Order in Queries
``````````````````````

For queries, the field order behavior is as follows:

- When comparing documents, field ordering is significant. For
example, when comparing documents with fields ``a`` and ``b`` in a
query:

- ``{a: 1, b: 1}`` is equal to ``{a: 1, b: 1}``

- ``{a: 1, b: 1}`` is not equal to ``{b: 1, a: 1}``

- For efficient query execution, the query engine may reorder fields
during query processing. Among other cases, reordering fields may
occur when processing these projection operators:
:pipeline:`$project`, :pipeline:`$addFields`, :pipeline:`$set`, and
:pipeline:`$unset`.

- Field reordering may occur in intermediate results as well as the
final results returned by a query.

- Because some operations may reorder fields, you should not rely on
specific field ordering in the results returned by a query that
uses the projection operators listed earlier.

Field Order in Write Operations
```````````````````````````````

.. include:: /includes/fact-update-field-order.rst
:start-after: order-of-document-fields

Expand Down
4 changes: 2 additions & 2 deletions source/includes/fact-update-field-order.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. order-of-document-fields

MongoDB preserves the order of the document fields following write
operations *except* for the following cases:
For write operations, MongoDB preserves the order of the document fields
*except* for the following cases:

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

Expand Down