summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2017-09-21 10:32:31 -0400
committerMatthew Russotto <matthew.russotto@10gen.com>2017-09-21 10:32:47 -0400
commitfc9b7c1f90017fbd84ce8350a52cc6052f7b465e (patch)
tree6aaf82d14bda1a50e9d1dc799499dfe097283341
parent0e3c8a96af7f9ddd6d5a059c92f6303eba1d0b32 (diff)
downloadmongo-fc9b7c1f90017fbd84ce8350a52cc6052f7b465e.tar.gz
SERVER-30722 Make changestreams require FCV 3.6
-rw-r--r--jstests/noPassthrough/change_stream_feature_compatibility_version.js27
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream.cpp9
2 files changed, 36 insertions, 0 deletions
diff --git a/jstests/noPassthrough/change_stream_feature_compatibility_version.js b/jstests/noPassthrough/change_stream_feature_compatibility_version.js
new file mode 100644
index 00000000000..9f12a7fd04b
--- /dev/null
+++ b/jstests/noPassthrough/change_stream_feature_compatibility_version.js
@@ -0,0 +1,27 @@
+// Test that $changeStreams usage is disallowed when the featureCompatibilityVersion is 3.4.
+(function() {
+ "use strict";
+
+ const rst = new ReplSetTest({nodes: 1});
+ rst.startSet();
+ rst.initiate();
+ const conn = rst.getPrimary();
+
+ const testDB = conn.getDB("changeStreams_feature_compatibility_version");
+ const coll = testDB.coll;
+ assert.commandWorked(testDB.createCollection(coll.getName()));
+
+ // Make sure $changeStreams works with (default) featureCompatibilityVersion 3.6
+
+ assert.commandWorked(testDB.runCommand(
+ {aggregate: coll.getName(), pipeline: [{$changeStream: {}}], cursor: {}}));
+
+ // $changeStreams is not permitted when the featureCompatibilityVersion is 3.4.
+
+ assert.commandWorked(testDB.adminCommand({setFeatureCompatibilityVersion: "3.4"}));
+ assert.commandFailedWithCode(
+ testDB.runCommand({aggregate: coll.getName(), pipeline: [{$changeStream: {}}], cursor: {}}),
+ ErrorCodes.InvalidOptions);
+
+ rst.stopSet();
+})();
diff --git a/src/mongo/db/pipeline/document_source_change_stream.cpp b/src/mongo/db/pipeline/document_source_change_stream.cpp
index 11ef4d20807..a38a1aef2ce 100644
--- a/src/mongo/db/pipeline/document_source_change_stream.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream.cpp
@@ -33,6 +33,7 @@
#include "mongo/bson/simple_bsonelement_comparator.h"
#include "mongo/db/bson/bson_helper.h"
#include "mongo/db/catalog/uuid_catalog.h"
+#include "mongo/db/commands/feature_compatibility_version_command_parser.h"
#include "mongo/db/pipeline/close_change_stream_exception.h"
#include "mongo/db/pipeline/document_source_check_resume_token.h"
#include "mongo/db/pipeline/document_source_limit.h"
@@ -231,6 +232,14 @@ BSONObj DocumentSourceChangeStream::buildMatchFilter(const NamespaceString& nss,
list<intrusive_ptr<DocumentSource>> DocumentSourceChangeStream::createFromBson(
BSONElement elem, const intrusive_ptr<ExpressionContext>& expCtx) {
+ uassert(
+ ErrorCodes::InvalidOptions,
+ str::stream()
+ << "The featureCompatibilityVersion must be 3.6 to use the $changeStream stage. See "
+ << feature_compatibility_version::kDochubLink
+ << ".",
+ serverGlobalParams.featureCompatibility.version.load() !=
+ ServerGlobalParams::FeatureCompatibility::Version::k34);
// TODO: Add sharding support here (SERVER-29141).
uassert(
40470, "The $changeStream stage is not supported on sharded systems.", !expCtx->inMongos);