- 
    Type:
Bug
 - 
    Resolution: Duplicate
 - 
    Priority:
Major - P3
 - 
    None
 - 
    Affects Version/s: None
 - 
    Component/s: None
 - 
    None
 
- 
        Query Optimization
 - 
        ALL
 - 
        QO 2022-10-31, QO 2022-11-14, QO 2022-11-28, QO 2022-12-12, QO 2022-12-26, QO 2023-01-09
 - 
        None
 
- 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 
The cause of the linked BF is that the given query is ambiguous - it asks for a field from $obj and then modifies obj in the same $project:
db.coll.aggregate( [{$project: {"time": "$obj.date", "obj": {$unsetField: {field: "text", input: {k: "text2", v: "$tag.assistant"}}}}}, {$sort: {_id: 1}}, {$limit: 20}] )
As a result, without optimization, $obj.date is missing; but with optimization, $addFields is added before $_internalUnpackBucket as part of stage reordering, resulting in $obj.date returning a value.
After discussing with Chris and Katya, both confirmed that we should make the output match the output of the non-optimized case. Alberto's suggestion for achieving this was that the optimization that moves $addFields before $internalUnpackBucket should be using an internal name rather than "obj", like:
"$addFields:" ( "kInternalName1" : { ...
- related to
 - 
                    
SERVER-66570 Timeseries pushes down metaField-projections that can change semantics
-         
 - Closed
 
 -