summaryrefslogtreecommitdiff
path: root/jstests/core/timeseries
diff options
context:
space:
mode:
authorAlison Lu <alison.lu@mongodb.com>2021-07-07 19:55:56 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-07 20:31:08 +0000
commit18c7d60f2e2cb494d5daa9e630d19c4f94e8a886 (patch)
tree55b329c86bc00f2ebc20c4954ac3b91ee2baa119 /jstests/core/timeseries
parenta21d8af14daec2222f7038b9a5756f5b87223076 (diff)
downloadmongo-18c7d60f2e2cb494d5daa9e630d19c4f94e8a886.tar.gz
SERVER-57734 Determine if an update's update document only modifies a timeseries collection's metaField
Diffstat (limited to 'jstests/core/timeseries')
-rw-r--r--jstests/core/timeseries/timeseries_update.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/jstests/core/timeseries/timeseries_update.js b/jstests/core/timeseries/timeseries_update.js
index 4ec9672cef5..980302ce72f 100644
--- a/jstests/core/timeseries/timeseries_update.js
+++ b/jstests/core/timeseries/timeseries_update.js
@@ -16,6 +16,7 @@ load("jstests/core/timeseries/libs/timeseries.js");
TimeseriesTest.run((insert) => {
const testDB = db.getSiblingDB(jsTestName());
assert.commandWorked(testDB.dropDatabase());
+
const coll = testDB.getCollection('t');
const timeFieldName = "time";
const metaFieldName = "tag";
@@ -93,5 +94,93 @@ TimeseriesTest.run((insert) => {
]
}),
ErrorCodes.InvalidOptions);
+
+ assert.commandWorked(insert(coll, {
+ [timeFieldName]: ISODate(),
+ [metaFieldName]: {c: "C", d: 2},
+ f1: [{"k": "K", "v": "V"}],
+ f2: 0,
+ f3: "f3",
+ }));
+
+ /*************************** Tests updating with an update document ***************************/
+ // Modify a field that is the metaField.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName]: {c: "C", d: 2}}, {$set: {[metaFieldName]: {e: "E"}}}),
+ ErrorCodes.IllegalOperation);
+
+ // Modify a field that is not the metaField.
+ assert.commandFailedWithCode(coll.update({[metaFieldName]: {c: "C", d: 2}}, {$set: {f2: "f2"}}),
+ ErrorCodes.InvalidOptions);
+
+ // Modify the metafield and fields that are not the metaField.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName]: {c: "C", d: 2}},
+ {$set: {[metaFieldName]: {e: "E"}, f3: "f3"}, $inc: {f2: 3}, $unset: {f1: ""}}),
+ ErrorCodes.InvalidOptions);
+
+ // Modify a field that is the metaField using dot notation.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName + ".c"]: "C"}, {$inc: {[metaFieldName + ".d"]: 10}}),
+ ErrorCodes.IllegalOperation);
+
+ // Modify the metaField multiple times.
+ assert.commandFailedWithCode(testDB.runCommand({
+ update: coll.getName(),
+ updates: [
+ {q: {[metaFieldName]: {c: "C", d: 2}}, u: {$set: {[metaFieldName]: 1}}},
+ {q: {[metaFieldName]: 1}, u: {$set: {[metaFieldName]: 2}}},
+ {q: {[metaFieldName]: 2}, u: {$set: {[metaFieldName]: 3}}}
+ ]
+ }),
+ ErrorCodes.IllegalOperation);
+
+ // Modify the metaField and a field that is not the metaField using dot notation.
+ assert.commandFailedWithCode(testDB.runCommand({
+ update: coll.getName(),
+ updates: [
+ {q: {[metaFieldName]: {c: "C", d: 2}}, u: {$inc: {[metaFieldName + ".d"]: 6}}},
+ {q: {[metaFieldName]: {c: "C", d: 8}}, u: {$set: {"f1.0": "f2"}}}
+ ]
+ }),
+ ErrorCodes.InvalidOptions);
+
+ /*************************** Tests updating with an update pipeline ***************************/
+ // Modify the metaField using dot notation: Add embedded fields to the metaField and remove an
+ // embedded field.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName + ".c"]: "C"},
+ [
+ {$set: {[metaFieldName + ".e"]: "E", [metaFieldName + ".f"]: "F"}},
+ {$unset: metaFieldName + ".d"}
+ ]),
+ ErrorCodes.IllegalOperation);
+
+ // Modify the metaField using dot notation: Remove an embedded field of the metaField
+ // and a field that is not the metaField.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName + ".c"]: "C"}, [{$unset: [metaFieldName + ".c", "f3"]}]),
+ ErrorCodes.InvalidOptions);
+
+ // Modify the metaField using dot notation: Add an embedded field and add a new field.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName + ".c"]: "C"}, [{$set: {[metaFieldName + ".e"]: "E", n: 1}}]),
+ ErrorCodes.InvalidOptions);
+
+ // Replace an entire document.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName + ".c"]: "C"},
+ [{$replaceWith: {_id: 4, t: ISODate(), [metaFieldName]: {"z": "Z"}}}]),
+ ErrorCodes.InvalidOptions);
+
+ /************************ Tests updating with a replacement document *************************/
+ // Replace a document to have no metaField.
+ assert.commandFailedWithCode(
+ coll.update({[metaFieldName]: {c: "C", d: 2}}, {f2: {e: "E", f: "F"}, f3: 7}),
+ ErrorCodes.InvalidOptions);
+
+ // Replace a document with an empty document.
+ assert.commandFailedWithCode(coll.update({[metaFieldName]: {c: "C", d: 2}}, {}),
+ ErrorCodes.InvalidOptions);
});
}());