diff options
author | James Wahlin <james@mongodb.com> | 2022-03-02 15:15:05 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-05 17:29:37 +0000 |
commit | 04f9e187c1ea2c2f5240c324b40c01712d4370a2 (patch) | |
tree | 47a0ce87f8509c8ff284ecb3c18b2b3f2ac8d9d7 /jstests | |
parent | 4f849e41dc7f4369cdc7e5892a60a4817800360d (diff) | |
download | mongo-04f9e187c1ea2c2f5240c324b40c01712d4370a2.tar.gz |
SERVER-64102 Ensure that unpacking measurements doesn't overwrite pushedown addFields that are computed on meta data
(cherry picked from commit 3a8cf3d2d1c6f668607756ab0b972f9ca2148f18)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/timeseries/timeseries_project.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/core/timeseries/timeseries_project.js b/jstests/core/timeseries/timeseries_project.js index 35c38da7426..9375f06240d 100644 --- a/jstests/core/timeseries/timeseries_project.js +++ b/jstests/core/timeseries/timeseries_project.js @@ -81,4 +81,36 @@ assert.docEq(result, [{_id: 0, time: docDate, a: {b: 1}, b: 4, c: [{}, {}]}]); // Test that an exclude does not overwrite meta field pushdown. result = coll.aggregate([{$unset: "b"}, {$set: {b: "$meta"}}]).toArray(); assert.docEq(result, [{_id: 0, time: docDate, meta: 4, a: {b: 1}, b: 4, c: [{}, {}]}]); + +// Test that a field reference in a projection refers to the stage's input document +// rather than another field with the same name in the projection. +(function() { +const regColl = db.timeseries_project_reg; +regColl.drop(); + +const tsColl = db.timeseries_project_ts; +tsColl.drop(); +assert.commandWorked( + db.createCollection(tsColl.getName(), {timeseries: {timeField: 'time', metaField: 'x'}})); + +const doc = { + time: new Date("2019-10-11T14:39:18.670Z"), + x: 5, + a: 3, +}; +assert.commandWorked(tsColl.insert(doc)); +assert.commandWorked(regColl.insert(doc)); + +// Test $project. +let pipeline = [{$project: {_id: 0, a: "$x", b: "$a"}}]; +let tsDoc = tsColl.aggregate(pipeline).toArray(); +let regDoc = regColl.aggregate(pipeline).toArray(); +assert.docEq(tsDoc, regDoc); + +// Test $addFields. +pipeline = [{$addFields: {a: "$x", b: "$a"}}, {$project: {_id: 0}}]; +tsDoc = tsColl.aggregate(pipeline).toArray(); +regDoc = regColl.aggregate(pipeline).toArray(); +assert.docEq(tsDoc, regDoc); +})(); })(); |