@@ -199,6 +199,37 @@ 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 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
+
202
233
.. include:: /includes/fact-update-field-order.rst
203
234
:start-after: order-of-document-fields
204
235
0 commit comments