The stage builders generate a plan that assumes a "root" document is available when it is not. E.g.
[j0:prim] [4] mkbson s16 [_id = s12, out = s15] true false [j0:prim] [4] project [s15 = getElement(s13, 0)] [j0:prim] [4] group [s12] [s13 = addToArrayCapped(s2, 104857600)] spillSlots[s14] mergingExprs[aggConcatArraysCapped(s14, 104857600)] [j0:prim] [4] project [s12 = (s11 ?: null)] [j0:prim] [4] project [s11 = traverseP(s10, lambda(l101.0) { getField(move(l101.0), "hostname") }, 1)] [j0:prim] [3] project [s10 = getField(s9, "tags")] [j0:prim] [3] mkbson s9 s4 [_id] keep [] true false [j0:prim] [2] sort [s7, s8] [desc, asc] [s2] [j0:prim] [2] project [s7 = [j0:prim] if (isArray(s3) ?: false) [j0:prim] then (_internalGreatest(s3) ?: undefined) [j0:prim] else (s3 ?: null) [j0:prim] , s8 = [j0:prim] if (isArray(s1) ?: false) [j0:prim] then (_internalLeast(s1) ?: undefined) [j0:prim] else (s1 ?: null) [j0:prim] ] [j0:prim] [2] project [s6 = (!((isArray(s3) ?: false)) || (!((isArray(s1) ?: false)) || fail(2, "cannot sort with keys that are parallel arrays")))] [j0:prim] [1] scan s4 s5 none none none none none none lowPriority [s1 = ExceededTimeLimit, s2 = _id, s3 = assertAlways] @"6f634a83-ec81-486b-a994-07d88e095f25" true false
This assumes s4 is available after the sort when in fact, only the _id value was carried through the sort.
The result is that the query fails due to a tassert.