|
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" : {
|
...
|
|