From 29b4478397ff8f1c4bb8375bfb0824ace09f1445 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Tue, 3 May 2022 13:38:35 +0100 Subject: [PATCH 1/8] Support clustered collections --- src/index.ts | 1 + src/operations/create_collection.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 965f584521..22da9e8e1f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -337,6 +337,7 @@ export type { IndexInformationOptions } from './operations/common_functions'; export type { CountOptions } from './operations/count'; export type { CountDocumentsOptions } from './operations/count_documents'; export type { + ClusteredCollectionOptions, CreateCollectionOptions, TimeSeriesCollectionOptions } from './operations/create_collection'; diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index ce8cf2b860..b1c4342928 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -41,6 +41,17 @@ export interface TimeSeriesCollectionOptions extends Document { granularity?: 'seconds' | 'minutes' | 'hours' | string; } +/** @public + * Configuration options for clustered collections + * @see https://www.mongodb.com/docs/v5.3/core/clustered-collections/ + */ +export interface ClusteredCollectionOptions extends Document { + name?: string; + key?: Document; + unique?: boolean; + v?: string; +} + /** @public */ export interface CreateCollectionOptions extends CommandOperationOptions { /** Returns an error if the collection does not exist */ @@ -73,7 +84,9 @@ export interface CreateCollectionOptions extends CommandOperationOptions { pkFactory?: PkFactory; /** A document specifying configuration options for timeseries collections. */ timeseries?: TimeSeriesCollectionOptions; - /** The number of seconds after which a document in a timeseries collection expires. */ + /** A document specifying configuration options for clustered collections. */ + clusteredIndex?: ClusteredCollectionOptions; + /** The number of seconds after which a document in a timeseries or clustered collection expires. */ expireAfterSeconds?: number; } From a0cfedf4f675000d1e0fafc0584b87dc04f707c9 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Tue, 3 May 2022 13:55:21 +0100 Subject: [PATCH 2/8] key and unique are actually required according to the scope --- src/operations/create_collection.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index b1c4342928..2daa45e093 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -47,8 +47,8 @@ export interface TimeSeriesCollectionOptions extends Document { */ export interface ClusteredCollectionOptions extends Document { name?: string; - key?: Document; - unique?: boolean; + key: Document; + unique: boolean; v?: string; } From 85bc6d9bb3b6a7848b2368bcece7e05d33ea91d2 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 4 May 2022 11:13:08 +0100 Subject: [PATCH 3/8] Include clustered boolean in the index description. --- src/operations/indexes.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index d7a27adfe0..18691b640d 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -95,6 +95,8 @@ export interface IndexDescription collation?: CollationOptions; name?: string; key: Document; + /* Specifies that this index is clustered. This is not a valid option to provide to 'createIndexes', but can appear in the options returned for an index via 'listIndexes'. */ + clustered?: boolean; } /** @public */ From a82720bb3f3ca7e55dcf1c1e836f6def54c65b5f Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 4 May 2022 11:30:18 +0100 Subject: [PATCH 4/8] spec-tests --- .../clustered-indexes.json | 176 ++++++++++++++++++ .../clustered-indexes.yml | 94 ++++++++++ 2 files changed, 270 insertions(+) create mode 100644 test/spec/collection-management/clustered-indexes.json create mode 100644 test/spec/collection-management/clustered-indexes.yml diff --git a/test/spec/collection-management/clustered-indexes.json b/test/spec/collection-management/clustered-indexes.json new file mode 100644 index 0000000000..3910f4d4f8 --- /dev/null +++ b/test/spec/collection-management/clustered-indexes.json @@ -0,0 +1,176 @@ +{ + "description": "clustered-indexes", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "5.3" + } + ], + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "ts-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "test" + } + } + ], + "initialData": [ + { + "collectionName": "test", + "databaseName": "ts-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "createCollection with clusteredIndex", + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "test" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "test", + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index" + } + } + }, + { + "name": "assertCollectionExists", + "object": "testRunner", + "arguments": { + "databaseName": "ts-tests", + "collectionName": "test" + } + } + ] + }, + { + "description": "listCollections includes clusteredIndex", + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "test" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "test", + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index" + } + } + }, + { + "name": "listCollections", + "object": "database0", + "arguments": { + "filter": { + "name": { + "$eq": "test" + } + } + }, + "expectResult": [ + { + "name": "test", + "options": { + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index", + "v": { + "$$type": [ + "int", + "long" + ] + } + } + } + } + ] + } + ] + }, + { + "description": "listIndexes returns the index", + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "test" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "test", + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index" + } + } + }, + { + "name": "listIndexes", + "object": "collection0", + "expectResult": [ + { + "key": { + "_id": 1 + }, + "name": "test index", + "clustered": true, + "unique": true, + "v": { + "$$type": [ + "int", + "long" + ] + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/spec/collection-management/clustered-indexes.yml b/test/spec/collection-management/clustered-indexes.yml new file mode 100644 index 0000000000..6e3163305d --- /dev/null +++ b/test/spec/collection-management/clustered-indexes.yml @@ -0,0 +1,94 @@ +description: "clustered-indexes" + +schemaVersion: "1.0" + +runOnRequirements: + - minServerVersion: "5.3" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name ts-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name test + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: [] + +tests: + - description: "createCollection with clusteredIndex" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0Name + - name: createCollection + object: *database0 + arguments: + collection: *collection0Name + clusteredIndex: + key: { _id: 1 } + unique: true + name: &index0Name "test index" + - name: assertCollectionExists + object: testRunner + arguments: + databaseName: *database0Name + collectionName: *collection0Name + + - description: "listCollections includes clusteredIndex" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0Name + - name: createCollection + object: *database0 + arguments: + collection: *collection0Name + clusteredIndex: + key: { _id: 1 } + unique: true + name: &index0Name "test index" + - name: listCollections + object: *database0 + arguments: + filter: { name: { $eq: *collection0Name } } + expectResult: + - name: *collection0Name + options: + clusteredIndex: + key: { _id: 1 } + unique: true + name: *index0Name + v: { $$type: [ int, long ] } + + - description: "listIndexes returns the index" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0Name + - name: createCollection + object: *database0 + arguments: + collection: *collection0Name + clusteredIndex: + key: { _id: 1 } + unique: true + name: *index0Name + - name: listIndexes + object: *collection0 + expectResult: + - key: { _id: 1 } + name: *index0Name + clustered: true + unique: true + v: { $$type: [ int, long ] } \ No newline at end of file From 685b985c4e7f9a8d07e609a5701fd4765943f04f Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 5 May 2022 10:36:06 +0100 Subject: [PATCH 5/8] TODO and ticket --- src/operations/create_collection.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index 2daa45e093..d8f1f4b6f6 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -43,6 +43,7 @@ export interface TimeSeriesCollectionOptions extends Document { /** @public * Configuration options for clustered collections + * TODO: NODE-4230 replace with normal manual link once it is on there. * @see https://www.mongodb.com/docs/v5.3/core/clustered-collections/ */ export interface ClusteredCollectionOptions extends Document { From 0d6a3edc6f895a448d532240d979a68dcebd90f4 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 5 May 2022 10:36:53 +0100 Subject: [PATCH 6/8] drop v --- src/operations/create_collection.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index d8f1f4b6f6..e2900b28b9 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -50,7 +50,6 @@ export interface ClusteredCollectionOptions extends Document { name?: string; key: Document; unique: boolean; - v?: string; } /** @public */ From 5f429cf5f1018b8eb3bbd1c1b45764f575c65f07 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 5 May 2022 10:37:46 +0100 Subject: [PATCH 7/8] comment --- src/operations/create_collection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operations/create_collection.ts b/src/operations/create_collection.ts index e2900b28b9..b96685fce5 100644 --- a/src/operations/create_collection.ts +++ b/src/operations/create_collection.ts @@ -84,7 +84,7 @@ export interface CreateCollectionOptions extends CommandOperationOptions { pkFactory?: PkFactory; /** A document specifying configuration options for timeseries collections. */ timeseries?: TimeSeriesCollectionOptions; - /** A document specifying configuration options for clustered collections. */ + /** A document specifying configuration options for clustered collections. For MongoDB 5.3 and above. */ clusteredIndex?: ClusteredCollectionOptions; /** The number of seconds after which a document in a timeseries or clustered collection expires. */ expireAfterSeconds?: number; From f92870e7148b827254015ee5994955553d85dfb1 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Thu, 5 May 2022 10:38:35 +0100 Subject: [PATCH 8/8] don't specify clustered --- src/operations/indexes.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index 18691b640d..d7a27adfe0 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -95,8 +95,6 @@ export interface IndexDescription collation?: CollationOptions; name?: string; key: Document; - /* Specifies that this index is clustered. This is not a valid option to provide to 'createIndexes', but can appear in the options returned for an index via 'listIndexes'. */ - clustered?: boolean; } /** @public */