Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-4189): Support clustered collections #3229

Merged
merged 8 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
15 changes: 14 additions & 1 deletion src/operations/create_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/
lerouxb marked this conversation as resolved.
Show resolved Hide resolved
*/
export interface ClusteredCollectionOptions extends Document {
name?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is optional and if left out the index will be named by the server automatically.

key: Document;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the scope, key is required. But right now the only valid valid is { _id: 1 }

unique: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the scope, unique is required. But right now it has to be set to true.

}

/** @public */
export interface CreateCollectionOptions extends CommandOperationOptions {
/** Returns an error if the collection does not exist */
Expand Down Expand Up @@ -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;
lerouxb marked this conversation as resolved.
Show resolved Hide resolved
/** The number of seconds after which a document in a timeseries or clustered collection expires. */
expireAfterSeconds?: number;
}

Expand Down
176 changes: 176 additions & 0 deletions test/spec/collection-management/clustered-indexes.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 ] }