If I want to add a sorting step into my aggregation pipeline which should sort the input documents according to two (or more) fields I can do so by adding a $sort stage (whose API is described here):
Given the current API the order in which the individual field sorting operations (sort by field1, then by field2, etc.) are applied is determined by the field order of the object that is assigned to the $sort property.
But this violates the ECMAScript spec...
E.g. ECMAScript 5 spec says that object properties are intrinsically unordered.
And ECMAScript 6 spec defines a specific object property order, but it does not equal to the order which the object properties have been defined in (see: https://esdiscuss.org/topic/nailing-object-property-order).
So it would be nice to have a $sort API that doesn't break the ECMAScript semantics, e.g. by using a strictly ordered data structure like an array: