-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
When an aggregation has two $sort stages on different keys that are NOT adjacent (so the optimizer cannot coalesce them), {$meta:"sortKey"} reflects the FIRST sort's key, not the effective final ordering produced by the last $sort. So it is effectively returning wrong results.
A common case would be when there is a view that defines sorting and a user wants to override it with its own sorting.
Note that the two sorts have to be not contiguous, which stage(s) sit in between don't matter at all