-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.0.12, 5.0.28, 6.0.17, 8.0.0-rc11
-
Component/s: None
-
Query Execution
-
Fully Compatible
-
ALL
-
v8.0, v7.3, v7.0, v6.0, v5.0
-
QE 2024-07-08
-
200
Consider the following pipeline:
[ {$documents: [{a: [1, 2, 3]}]}, {$project: {"a.b": 1}}, {$addFields: {"a.c": "why?"}} ]
Inclusion $project on a sub-field of an array will remove all scalar values, making array “a” empty.
$addFields on a sub-field of an array will add
to every element of the array, but array is empty, so the expected answer would be
[{a: []}]
However, we get
{ a: [ { c: 'why?' }, { c: 'why?' }, { c: 'why?' } ] }
because $project actually doesn't remove scalars, but replacing them with MISSING values.
This is a bug. Especially given it behaves inconsistently with reading from disk,
because this pipeline will return correct result.
Consider a collection test with a single document
db.test.aggregate([{$project: {_id: 0, "a.b": 1}}, {$addFields: {"a.c": "why?"}}]).
It will return correctly, because if Document has a backing BSONObj, it will use fast-path projection that actually removes elements from the array.
- is related to
-
SERVER-96476 Adding 'missing' field to MutableDocument may change the order of subsequent inserts
- Backlog