-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Fully Compatible
-
QO 2021-11-01
Example:
db.products.aggregate({$match:{type:"HardGood","details.name":{$exists:true}}}, {$unwind:{path:"$details", preserveNullAndEmptyArrays:true}},{$limit:100},{$project:{_id:0,"details.name":1}})
will return the same results as
db.products.aggregate({$match:{type:"HardGood","details.name":{$exists:true}}},{$limit:100}, {$unwind:{path:"$details", preserveNullAndEmptyArrays:true}},{$limit:100},{$project:{_id:0,"details.name":1}})
but the second one will be able to push $limit 100 down to the query subsystem and reduce number of documents (or index entries) scanned from entire collection or entire set matching the predicate to 101.
This is similar to pushing $sort in front of $unwind in cases where sorting is done on field that's not involved in unwinding. SERVER-26442