From c7f5e389e4488fcf7bd7a9a2ca4149080c409242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20G=C3=B3mez=20Ferro?= Date: Wed, 2 Feb 2022 07:59:01 +0000 Subject: SERVER-62811 Allow special index types on cluster keys --- jstests/core/clustered_collection_creation.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'jstests') diff --git a/jstests/core/clustered_collection_creation.js b/jstests/core/clustered_collection_creation.js index 3c24f860526..34b5d39a8a6 100644 --- a/jstests/core/clustered_collection_creation.js +++ b/jstests/core/clustered_collection_creation.js @@ -6,7 +6,7 @@ * non-replicated collections. * * @tags: [ - * requires_fcv_52, + * requires_fcv_53, * assumes_against_mongod_not_mongos, * assumes_no_implicit_collection_creation_after_drop, * does_not_support_stepdowns, @@ -38,6 +38,12 @@ const validateCompoundSecondaryIndexes = function(db, coll, clusterKey) { coll.drop(); }; +const overrideIndexType = function(clusterKey, indexType) { + for (const field of Object.keys(clusterKey)) { + return Object.assign(Object.assign({}, clusterKey), {[field]: indexType}); + } +}; + // Tests it is legal to call createIndex on the cluster key with or without {'clustered': true} as // an option. Additionally, confirms it is illegal to call createIndex with the 'clustered' option // on a pattern that is not the cluster key. @@ -75,6 +81,15 @@ const validateCreateIndexOnClusterKey = function(db, collName, fullCreateOptions const listIndexes1 = assert.commandWorked(db[collName].runCommand("listIndexes")); assert.eq(listIndexes1.cursor.firstBatch.length, 1); assert.docEq(listIndexes1.cursor.firstBatch[0], listIndexes0.cursor.firstBatch[0]); + + // It's possible to create 'hashed','2d','2dsphere' and 'text' indexes on the cluster key. + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, 'hashed'))); + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, '2d'))); + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, '2dsphere'))); + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, 'text'))); + + const finalIndexes = assert.commandWorked(db[collName].runCommand("listIndexes")); + assert.eq(finalIndexes.cursor.firstBatch.length, 5); }; // It is illegal to drop the clusteredIndex. Verify that the various ways of dropping the -- cgit v1.2.1