summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-03-04 20:18:06 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-05 01:41:59 +0000
commit61318eac667529756fe30ed7493772ebc6e8759e (patch)
treee95a35f3461c5084cb87d25288e36e409fb88698
parent8641dd510c5d2b6fe8f58f221ff4fe724f9267a7 (diff)
downloadmongo-61318eac667529756fe30ed7493772ebc6e8759e.tar.gz
SERVER-54646 support hiding/unhiding indexes by name on time-series collections
-rw-r--r--jstests/core/timeseries/timeseries_index.js11
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp4
2 files changed, 14 insertions, 1 deletions
diff --git a/jstests/core/timeseries/timeseries_index.js b/jstests/core/timeseries/timeseries_index.js
index 7d9778fb5f1..8548b1f8885 100644
--- a/jstests/core/timeseries/timeseries_index.js
+++ b/jstests/core/timeseries/timeseries_index.js
@@ -86,6 +86,17 @@ const runTest = function(keyForCreate, hint) {
assert.commandWorked(coll.createIndex(keyForCreate, {name: 'myindex2'}),
'failed to create index: ' + tojson(keyForCreate));
assert.commandWorked(coll.dropIndexes(['myindex2']), 'failed to drop indexes: [myindex2]');
+
+ // Check that we are able to hide and unhide the index by name.
+ assert.commandWorked(coll.createIndex(keyForCreate, {name: 'hide1'}),
+ 'failed to create index: ' + tojson(keyForCreate));
+ assert.eq(1, bucketsColl.find().hint(hint).toArray().length);
+ assert.commandWorked(coll.hideIndex('hide1'), 'failed to hide index: hide1');
+ assert.commandFailedWithCode(assert.throws(() => bucketsColl.find().hint(hint).toArray()),
+ ErrorCodes.BadValue);
+ assert.commandWorked(coll.unhideIndex('hide1'), 'failed to unhide index: hide1');
+ assert.eq(1, bucketsColl.find().hint(hint).toArray().length);
+ assert.commandWorked(coll.dropIndex('hide1'), 'failed to drop index: hide1');
};
runTest({[metaFieldName]: 1}, {meta: 1});
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index 7065b4ec96b..6ada21aa489 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -237,7 +237,9 @@ StatusWith<CollModRequest> parseCollModRequest(OperationContext* opCtx,
}
// Disallow index hiding/unhiding on system collections.
- if (nss.isSystem()) {
+ // Bucket collections, which hold data for user-created time-series collections, do
+ // not have this restriction.
+ if (nss.isSystem() && !nss.isTimeseriesBucketsCollection()) {
return Status(ErrorCodes::BadValue, "Can't hide index on system collection");
}