Skip to content

Commit

Permalink
feat(NODE-4189): Add support for clustered collections (#3229)
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed May 5, 2022
1 parent d216725 commit 79a917b
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -348,6 +348,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';
Expand Down
15 changes: 14 additions & 1 deletion src/operations/create_collection.ts
Expand Up @@ -42,6 +42,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 */
Expand Down Expand Up @@ -74,7 +85,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;
/** @experimental */
encryptedFields?: Document;
Expand Down
176 changes: 176 additions & 0 deletions 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"
]
}
}
]
}
]
}
]
}
94 changes: 94 additions & 0 deletions 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 ] }

0 comments on commit 79a917b

Please sign in to comment.