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