diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-09-02 12:39:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-02 13:37:58 +0000 |
commit | 26d222d66fbb97152b283a63f8e6393171c8710f (patch) | |
tree | 8cd96052ef517d5127e7acdfe3aa63539ff825ec | |
parent | 97cdfef9e4f74918176f1916bc53ada8f9f66868 (diff) | |
download | mongo-26d222d66fbb97152b283a63f8e6393171c8710f.tar.gz |
SERVER-5972 Allow `system.js` to be dropped
-rw-r--r-- | jstests/core/system_js_drop.js | 37 | ||||
-rw-r--r-- | src/mongo/db/catalog/database_impl.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/op_observer/op_observer_impl.cpp | 3 |
3 files changed, 42 insertions, 1 deletions
diff --git a/jstests/core/system_js_drop.js b/jstests/core/system_js_drop.js new file mode 100644 index 00000000000..49a59c14ed5 --- /dev/null +++ b/jstests/core/system_js_drop.js @@ -0,0 +1,37 @@ +/** + * Tests dropping the system.js collection. + * + * @tags: [ + * assumes_read_preference_unchanged, + * assumes_unsharded_collection, + * requires_fcv_62, + * requires_non_retryable_writes, + * ] + */ +(function() { +'use strict'; + +const testDB = db.getSiblingDB(jsTestName()); +assert.commandWorked(testDB.dropDatabase()); + +const coll = testDB.coll; +const systemJs = testDB.system.js; + +assert.commandWorked(coll.insert([{name: 'Alice', age: 20}, {name: 'Bob', age: 18}])); + +assert.commandWorked(systemJs.insert({ + _id: "isTeenager", + value: function(age) { + return age >= 13 && age <= 19; + }, +})); + +assert.commandWorked( + testDB.runCommand({find: coll.getName(), filter: {$where: "isTeenager(this.age)"}})); + +assert(systemJs.drop()); + +assert.commandFailedWithCode( + testDB.runCommand({find: coll.getName(), filter: {$where: "isTeenager(this.age)"}}), + ErrorCodes.JSInterpreterFailure); +})(); diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index dfa0d846762..28c3fa2e8cb 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -423,7 +423,8 @@ Status DatabaseImpl::dropCollection(OperationContext* opCtx, nss == NamespaceString::kKeysCollectionNamespace || nss.isTemporaryReshardingCollection() || nss.isTimeseriesBucketsCollection() || nss.isChangeStreamPreImagesCollection() || - nss == NamespaceString::kConfigsvrRestoreNamespace || nss.isChangeCollection(); + nss == NamespaceString::kConfigsvrRestoreNamespace || nss.isChangeCollection() || + nss.isSystemDotJavascript(); }; if (nss.isSystem()) { diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp index 00f0ddc253d..7350a487db8 100644 --- a/src/mongo/db/op_observer/op_observer_impl.cpp +++ b/src/mongo/db/op_observer/op_observer_impl.cpp @@ -1357,6 +1357,9 @@ repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx, ReadWriteConcernDefaults::get(opCtx).invalidate(); } else if (collectionName.isTimeseriesBucketsCollection()) { BucketCatalog::get(opCtx).clear(collectionName.getTimeseriesViewNamespace()); + } else if (collectionName.isSystemDotJavascript()) { + // Inform the JavaScript engine of the change to system.js. + Scope::storedFuncMod(opCtx); } return {}; |