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..b96685fce5 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 + * 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 { + name?: string; + key: Document; + unique: boolean; +} + /** @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. 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; } 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