summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/noPassthrough/timeseries_change_streams.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/noPassthrough/timeseries_change_streams.js b/jstests/noPassthrough/timeseries_change_streams.js
new file mode 100644
index 00000000000..e75a0ac740e
--- /dev/null
+++ b/jstests/noPassthrough/timeseries_change_streams.js
@@ -0,0 +1,60 @@
+// Tests that $changeStream aggregations against time-series collections fail cleanly.
+// @tags: [
+// requires_fcv_50,
+// requires_timeseries,
+// ]
+(function() {
+"use strict";
+
+load("jstests/core/timeseries/libs/timeseries.js"); // For TimeseriesTest.
+load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
+load("jstests/libs/change_stream_util.js"); // For ChangeStreamTest and
+ // assert[Valid|Invalid]ChangeStreamNss.
+
+const rst = new ReplSetTest({nodes: 1});
+rst.startSet();
+rst.initiate();
+
+const timeFieldName = "time";
+const metaFieldName = "tags";
+const testDB = rst.getPrimary().getDB(jsTestName());
+assert.commandWorked(testDB.dropDatabase());
+
+if (!TimeseriesTest.timeseriesCollectionsEnabled(testDB.getMongo())) {
+ jsTestLog("Skipping test because the time-series collection feature flag is disabled");
+ MongoRunner.stopMongod(conn);
+ return;
+}
+
+const tsColl = testDB.getCollection("ts_point_data");
+tsColl.drop();
+
+assert.commandWorked(testDB.createCollection(
+ tsColl.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
+
+const nMeasurements = 10;
+
+for (let i = 0; i < nMeasurements; i++) {
+ const docToInsert = {
+ time: ISODate(),
+ tags: i.toString(),
+ value: i + nMeasurements,
+ };
+ assert.commandWorked(tsColl.insert(docToInsert));
+}
+
+// Test that a changeStream cannot be opened on 'system.buckets.X' collections.
+assert.commandFailedWithCode(testDB.runCommand({
+ aggregate: "system.buckets." + tsColl.getName(),
+ pipeline: [{$changeStream: {}}],
+ cursor: {}
+}),
+ ErrorCodes.InvalidNamespace);
+
+// Test that a changeStream cannot be opened on a time-series collection because it's a view.
+assert.commandFailedWithCode(
+ testDB.runCommand({aggregate: tsColl.getName(), pipeline: [{$changeStream: {}}], cursor: {}}),
+ ErrorCodes.CommandNotSupportedOnView);
+
+rst.stopSet();
+})();