@@ -12,7 +12,7 @@ Compatibility Changes in MongoDB 3.6
12
12
13
13
The following 3.6 changes can affect the compatibility with older
14
14
versions of MongoDB.
15
-
15
+
16
16
.. _3.6-bind_ip-compatibility:
17
17
18
18
Localhost Binding Compatibility Changes
@@ -233,6 +233,75 @@ For more information on sorting with the
233
233
:doc:`Aggregation Pipeline </reference/operator/aggregation/>`, see
234
234
:doc:`$sort </reference/operator/aggregation/sort/>`.
235
235
236
+ Sorting with a Compound Sort Pattern on Multiple Array Fields with ``aggregate``
237
+ ````````````````````````````````````````````````````````````````````````````````
238
+
239
+ In MongoDB 3.6, when sorting in an
240
+ :doc:`aggregation pipeline </core/aggregation-pipeline/>`, MongoDB can
241
+ no longer sort with keys that are *parallel arrays*. Arrays are
242
+ considered parallel if they are sibling elements of the BSON object.
243
+ Sort keys involving nested arrays are not considered parallel, nor are
244
+ sort keys which share the same array as a prefix.
245
+
246
+ .. note::
247
+
248
+ This behavior has always existed for sorting with
249
+ :method:`find <db.collection.find()>`, but now in 3.6
250
+ :method:`find <db.collection.find()>` and
251
+ :method:`aggregate <db.collection.aggregate()>` share the same
252
+ semantics.
253
+
254
+ .. example::
255
+
256
+ A collection contains the following document:
257
+
258
+ .. code-block:: javascript
259
+
260
+ {a: [ {b: [1, 2]}, {b: [3, 4]} ]}
261
+
262
+ The following aggregation succeeds because the sort is performed on
263
+ a nested array:
264
+
265
+ .. code-block:: javascript
266
+
267
+ db.coll.aggregate([{$sort: {"a.b": 1}}])
268
+
269
+ .. example::
270
+
271
+ Similarly, if a collection contains the following document:
272
+
273
+ .. code-block:: javascript
274
+
275
+ {a: [{b: 1, c: 1}, {b: 2, c: 2}]}
276
+
277
+ The following aggregation succeeds because the sort keys share the
278
+ same array as a prefix:
279
+
280
+ .. code-block:: javascript
281
+
282
+ db.coll.aggregate([{$sort: {"a.b": 1, "a.c": 1}}])
283
+
284
+ .. example::
285
+
286
+ However, in a collection that contains the following documents:
287
+
288
+ .. code-block:: javascript
289
+
290
+ { _id: 1, a: [ 1, 2 ], b: [ 1, 2 ]}
291
+ { _id: 2, a: [ -3, 5 ], b: 0 }
292
+ { _id: 3, a: [ -6, 12 ], b: 100 }
293
+
294
+ The following sort operation fails:
295
+
296
+ .. code-block:: javascript
297
+
298
+ db.coll.aggregate([ { $sort: {a: 1, b: 1} } ])
299
+
300
+ MongoDB cannot sort on both the ``a`` and ``b`` fields because
301
+ in the document with ``_id : 1`` , both the ``a`` and ``b`` fields
302
+ are arrays. As a result, MongoDB encounters a parallel array during
303
+ sort key generation and returns an error.
304
+
236
305
Update Operation Changes
237
306
------------------------
238
307
0 commit comments