@@ -199,6 +199,36 @@ Document Size Limit
199
199
Document Field Order
200
200
~~~~~~~~~~~~~~~~~~~~
201
201
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
+
202
232
.. include:: /includes/fact-update-field-order.rst
203
233
:start-after: order-of-document-fields
204
234
0 commit comments