summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-04-12 06:44:47 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-12 11:09:27 +0000
commit27e0cb191d1c26ea5fc78f3b81ebd3fedafd8126 (patch)
tree1b8de4f90e73ccea1b24ebe2b5bce96d7e20136c
parentfaa1f8247ce659bde4115326d5ba1e14b3d52d9e (diff)
downloadmongo-27e0cb191d1c26ea5fc78f3b81ebd3fedafd8126.tar.gz
SERVER-55994 add tests for user hints on time-series collection queries
-rw-r--r--jstests/core/timeseries/timeseries_index.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/jstests/core/timeseries/timeseries_index.js b/jstests/core/timeseries/timeseries_index.js
index 5bfd4aba516..c08260a67d5 100644
--- a/jstests/core/timeseries/timeseries_index.js
+++ b/jstests/core/timeseries/timeseries_index.js
@@ -145,6 +145,26 @@ const runTest = function(keyForCreate, hint) {
assert.eq(1, bucketsColl.find().hint(hint).toArray().length);
assert.eq(1, coll.find().hint(hint).toArray().length);
assert.commandWorked(coll.dropIndex('hide3'), 'failed to drop index: hide3');
+
+ // Check that user hints on queries will be allowed and will reference the indexes on the
+ // buckets collection directly.
+ assert.commandWorked(coll.createIndex(keyForCreate, {name: 'index_for_hint_test'}),
+ 'failed to create index index_for_hint_test: ' + tojson(keyForCreate));
+ // Specifying the index by name should work on both the time-series collection and the
+ // underlying buckets collection.
+ assert.eq(1, bucketsColl.find().hint('index_for_hint_test').toArray().length);
+ assert.eq(1, coll.find().hint('index_for_hint_test').toArray().length);
+ // Specifying the index by key pattern should work when we use the underlying buckets
+ // collection's schema.
+ assert.eq(1, bucketsColl.find().hint(hint).toArray().length);
+ assert.eq(1, coll.find().hint(hint).toArray().length);
+ // Specifying the index by key pattern on the time-series collection should not work.
+ assert.commandFailedWithCode(
+ assert.throws(() => bucketsColl.find().hint(keyForCreate).toArray()), ErrorCodes.BadValue);
+ assert.commandFailedWithCode(assert.throws(() => coll.find().hint(keyForCreate).toArray()),
+ ErrorCodes.BadValue);
+ assert.commandWorked(coll.dropIndex('index_for_hint_test'),
+ 'failed to drop index: index_for_hint_test');
};
/**