Skip to content

Commit fc9b7c1

Browse files
committed
SERVER-30722 Make changestreams require FCV 3.6
1 parent 0e3c8a9 commit fc9b7c1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Test that $changeStreams usage is disallowed when the featureCompatibilityVersion is 3.4.
2+
(function() {
3+
"use strict";
4+
5+
const rst = new ReplSetTest({nodes: 1});
6+
rst.startSet();
7+
rst.initiate();
8+
const conn = rst.getPrimary();
9+
10+
const testDB = conn.getDB("changeStreams_feature_compatibility_version");
11+
const coll = testDB.coll;
12+
assert.commandWorked(testDB.createCollection(coll.getName()));
13+
14+
// Make sure $changeStreams works with (default) featureCompatibilityVersion 3.6
15+
16+
assert.commandWorked(testDB.runCommand(
17+
{aggregate: coll.getName(), pipeline: [{$changeStream: {}}], cursor: {}}));
18+
19+
// $changeStreams is not permitted when the featureCompatibilityVersion is 3.4.
20+
21+
assert.commandWorked(testDB.adminCommand({setFeatureCompatibilityVersion: "3.4"}));
22+
assert.commandFailedWithCode(
23+
testDB.runCommand({aggregate: coll.getName(), pipeline: [{$changeStream: {}}], cursor: {}}),
24+
ErrorCodes.InvalidOptions);
25+
26+
rst.stopSet();
27+
})();

src/mongo/db/pipeline/document_source_change_stream.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "mongo/bson/simple_bsonelement_comparator.h"
3434
#include "mongo/db/bson/bson_helper.h"
3535
#include "mongo/db/catalog/uuid_catalog.h"
36+
#include "mongo/db/commands/feature_compatibility_version_command_parser.h"
3637
#include "mongo/db/pipeline/close_change_stream_exception.h"
3738
#include "mongo/db/pipeline/document_source_check_resume_token.h"
3839
#include "mongo/db/pipeline/document_source_limit.h"
@@ -231,6 +232,14 @@ BSONObj DocumentSourceChangeStream::buildMatchFilter(const NamespaceString& nss,
231232

232233
list<intrusive_ptr<DocumentSource>> DocumentSourceChangeStream::createFromBson(
233234
BSONElement elem, const intrusive_ptr<ExpressionContext>& expCtx) {
235+
uassert(
236+
ErrorCodes::InvalidOptions,
237+
str::stream()
238+
<< "The featureCompatibilityVersion must be 3.6 to use the $changeStream stage. See "
239+
<< feature_compatibility_version::kDochubLink
240+
<< ".",
241+
serverGlobalParams.featureCompatibility.version.load() !=
242+
ServerGlobalParams::FeatureCompatibility::Version::k34);
234243
// TODO: Add sharding support here (SERVER-29141).
235244
uassert(
236245
40470, "The $changeStream stage is not supported on sharded systems.", !expCtx->inMongos);

0 commit comments

Comments
 (0)