summaryrefslogtreecommitdiff
path: root/jstests/core/timeseries/timeseries_project.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/timeseries/timeseries_project.js')
-rw-r--r--jstests/core/timeseries/timeseries_project.js185
1 files changed, 1 insertions, 184 deletions
diff --git a/jstests/core/timeseries/timeseries_project.js b/jstests/core/timeseries/timeseries_project.js
index b735a8a3b66..9375f06240d 100644
--- a/jstests/core/timeseries/timeseries_project.js
+++ b/jstests/core/timeseries/timeseries_project.js
@@ -4,7 +4,7 @@
* @tags: [
* does_not_support_stepdowns,
* does_not_support_transactions,
- * requires_fcv_60,
+ * requires_fcv_53,
* ]
*/
(function() {
@@ -97,7 +97,6 @@ const doc = {
time: new Date("2019-10-11T14:39:18.670Z"),
x: 5,
a: 3,
- obj: {a: 3},
};
assert.commandWorked(tsColl.insert(doc));
assert.commandWorked(regColl.insert(doc));
@@ -108,192 +107,10 @@ let tsDoc = tsColl.aggregate(pipeline).toArray();
let regDoc = regColl.aggregate(pipeline).toArray();
assert.docEq(tsDoc, regDoc);
-pipeline = [{$project: {_id: 0, obj: "$x", b: {$add: ["$obj.a", 1]}}}];
-tsDoc = tsColl.aggregate(pipeline).toArray();
-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);
-
-pipeline = [{$addFields: {obj: "$x", b: {$add: ["$obj.a", 1]}}}, {$project: {_id: 0}}];
-tsDoc = tsColl.aggregate(pipeline).toArray();
-regDoc = regColl.aggregate(pipeline).toArray();
-assert.docEq(tsDoc, regDoc);
-
-pipeline = [{$project: {a: 1, _id: 0}}, {$project: {newMeta: "$x"}}];
-tsDoc = tsColl.aggregate(pipeline).toArray();
-regDoc = regColl.aggregate(pipeline).toArray();
-assert.docEq(tsDoc, regDoc);
-})();
-
-// Test that an includes projection that doesn't include previously included computed meta fields
-// outputs correctly.
-(function testIncludeComputedMetaFieldThenProjectWithoutComputedMetaField() {
- coll.drop();
- assert.commandWorked(
- db.createCollection(coll.getName(), {timeseries: {timeField: 'time', metaField: 'tag'}}));
-
- const doc = {_id: 0, time: ISODate("2024-01-01T00:00:00.000Z"), tag: {field: "A"}};
- assert.commandWorked(coll.insert(doc));
- let result = {};
-
- // Added field which uses meta should not be in the result.
- result =
- coll.aggregate(
- [{$addFields: {time: {$dateFromParts: {year: "$tag.none"}}}}, {$project: {tag: 1}}])
- .toArray();
- assert.docEq([{"tag": {"field": "A"}, "_id": 0}], result);
-
- // Test with non-null value.
- result = coll.aggregate([{$addFields: {time: {$toLower: "$tag.field"}}}, {$project: {tag: 1}}])
- .toArray();
- assert.docEq([{"tag": {"field": "A"}, "_id": 0}], result);
-
- // Testing with $match between $addFields and $project.
- result = coll.aggregate([
- {$addFields: {time: {$dateFromParts: {year: "$tag.none"}}}},
- {$match: {tag: {field: "A"}}},
- {$project: {tag: 1}}
- ])
- .toArray();
- assert.docEq([{"tag": {field: "A"}, "_id": 0}], result);
-
- // Test with non-null value.
- result =
- coll.aggregate(
- [{$addFields: {time: "$tag.field"}}, {$match: {time: "A"}}, {$project: {tag: 1}}])
- .toArray();
- assert.docEq([{"tag": {field: "A"}, "_id": 0}], result);
-
- // Testing with $project after $project.
- result = coll.aggregate([{$project: {tag: 1}}, {$project: {time: 1}}]).toArray();
- assert.docEq([{"_id": 0}], result);
-
- // Testing with $set.
- result = coll.aggregate([{$set: {tag: "$tag.field"}}, {$project: {time: 1}}]).toArray();
- assert.docEq([{"_id": 0, "time": ISODate("2024-01-01T00:00:00Z")}], result);
-
- // Test that computedMetaFields that are included by the $project are still included.
- result = coll.aggregate([
- {$addFields: {hi: {$dateFromParts: {year: "$tag.none"}}}},
- {$addFields: {bye: {$dateFromParts: {year: "$tag.none"}}}},
- {$project: {hi: 1}}
- ])
- .toArray();
- assert.docEq([{"_id": 0, "hi": null}], result);
-
- // Test with non-null value.
- result = coll.aggregate([
- {$addFields: {hi: "$tag.field"}},
- {$addFields: {bye: "$tag.field"}},
- {$project: {hi: 1}}
- ])
- .toArray();
- assert.docEq([{"_id": 0, "hi": "A"}], result);
-
- // Test that $project that replaces field that is used works.
- result = coll.aggregate([
- {$addFields: {hello: "$tag.field"}},
- {$project: {newTime: "$time", time: "$tag.field"}}
- ])
- .toArray();
-
- assert.docEq([{"_id": 0, newTime: ISODate("2024-01-01T00:00:00.000Z"), time: "A"}], result);
-
- // Test adding fields and including one of them.
- result = coll.aggregate([
- {$addFields: {a: {$toLower: "$tag.field"}}},
- {$addFields: {b: {$toUpper: "$tag.field"}}},
- {$project: {b: 1}}
- ])
- .toArray();
- assert.docEq([{b: "A", "_id": 0}], result);
-})();
-
-// Test that an excludes projection that excludes previously included computed meta fields
-// outputs correctly.
-(function testIncludeComputedMetaFieldThenExcludeComputedMetaField() {
- coll.drop();
- assert.commandWorked(
- db.createCollection(coll.getName(), {timeseries: {timeField: 'time', metaField: 'tag'}}));
-
- const doc = {_id: 0, time: ISODate("2024-01-01T00:00:00.000Z"), tag: {field: "A"}};
- assert.commandWorked(coll.insert(doc));
- let result = {};
-
- // Excluded '_computedMetaProjField' should not be included.
- result = coll.aggregate([
- {$addFields: {hello: {$dateFromParts: {year: "$tag.none"}}}},
- {$project: {hello: 0}}
- ])
- .toArray();
- assert.docEq([{"time": ISODate("2024-01-01T00:00:00Z"), "tag": {"field": "A"}, "_id": 0}],
- result);
-
- // Test with non-null value.
- result = coll.aggregate([{$addFields: {time: {$toLower: "$tag.field"}}}, {$project: {time: 0}}])
- .toArray();
- assert.docEq([{"tag": {"field": "A"}, "_id": 0}], result);
-
- // Testing with $match between $addFields and $project.
- result = coll.aggregate([
- {$addFields: {time: {$dateFromParts: {year: "$tag.none"}}}},
- {$match: {tag: {field: "A"}}},
- {$project: {time: 0}}
- ])
- .toArray();
- assert.docEq([{"tag": {field: "A"}, "_id": 0}], result);
-
- // Test with non-null value.
- result =
- coll.aggregate(
- [{$addFields: {time: "$tag.field"}}, {$match: {time: "A"}}, {$project: {time: 0}}])
- .toArray();
- assert.docEq([{"tag": {field: "A"}, "_id": 0}], result);
-
- // Testing with exclude $project after include $project.
- result = coll.aggregate([{$project: {tag: 1}}, {$project: {tag: 0}}]).toArray();
- assert.docEq([{"_id": 0}], result);
-
- // Testing with $set.
- result = coll.aggregate([{$set: {tag: "$tag.field"}}, {$project: {tag: 0}}]).toArray();
- assert.docEq([{"time": ISODate("2024-01-01T00:00:00Z"), "_id": 0}], result);
-
- // Exclude one added field.
- result = coll.aggregate([
- {$addFields: {hi: {$dateFromParts: {year: "$tag.none"}}}},
- {$addFields: {bye: {$dateFromParts: {year: "$tag.none"}}}},
- {$project: {hi: 0}}
- ])
- .toArray();
- assert.docEq(
- [{"time": ISODate("2024-01-01T00:00:00Z"), "tag": {"field": "A"}, "_id": 0, "bye": null}],
- result);
-
- // Test with non-null value.
- result = coll.aggregate([
- {$addFields: {hi: "$tag.field"}},
- {$addFields: {bye: "$tag.field"}},
- {$project: {hi: 0}}
- ])
- .toArray();
- assert.docEq(
- [{"time": ISODate("2024-01-01T00:00:00Z"), "tag": {"field": "A"}, "_id": 0, "bye": "A"}],
- result);
-
- // Test adding fields and excluding one of them.
- result = coll.aggregate([
- {$addFields: {a: {$toLower: "$tag.field"}}},
- {$addFields: {b: {$toUpper: "$tag.field"}}},
- {$project: {b: 0}}
- ])
- .toArray();
- assert.docEq(
- [{"time": ISODate("2024-01-01T00:00:00Z"), "tag": {"field": "A"}, "_id": 0, "a": "a"}],
- result);
})();
})();