Currently, the replaceRoot match pushdown includes a rewritten match expression with an additional {$expr: {$ne: [{$type: ['$subDocument']}, {$const: 'object'}]}} predicate to maintain the invariant that all documents in the collection must have a value at "newField" that resolves to an object. Since a match with $expr can't be pushed down before replaceRoot due to a performance slowdown in converting BSONObj to Document, investigate a non-$expr rewrite alternative.
The proposed alternative is {$or: [\{"subDocument": {$type: "array"}}, \\{"subDocument": {$not: {$type: "object"}}}]}
- is related to
-
SERVER-89382 Disallow match pushdown for replaceRoot if match contains $expr
- Closed