Skip to content

Commit 79a917b

Browse files
authored
feat(NODE-4189): Add support for clustered collections (#3229)
1 parent d216725 commit 79a917b

File tree

4 files changed

+285
-1
lines changed

4 files changed

+285
-1
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export type { IndexInformationOptions } from './operations/common_functions';
348348
export type { CountOptions } from './operations/count';
349349
export type { CountDocumentsOptions } from './operations/count_documents';
350350
export type {
351+
ClusteredCollectionOptions,
351352
CreateCollectionOptions,
352353
TimeSeriesCollectionOptions
353354
} from './operations/create_collection';

src/operations/create_collection.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ export interface TimeSeriesCollectionOptions extends Document {
4242
granularity?: 'seconds' | 'minutes' | 'hours' | string;
4343
}
4444

45+
/** @public
46+
* Configuration options for clustered collections
47+
* TODO: NODE-4230 replace with normal manual link once it is on there.
48+
* @see https://www.mongodb.com/docs/v5.3/core/clustered-collections/
49+
*/
50+
export interface ClusteredCollectionOptions extends Document {
51+
name?: string;
52+
key: Document;
53+
unique: boolean;
54+
}
55+
4556
/** @public */
4657
export interface CreateCollectionOptions extends CommandOperationOptions {
4758
/** Returns an error if the collection does not exist */
@@ -74,7 +85,9 @@ export interface CreateCollectionOptions extends CommandOperationOptions {
7485
pkFactory?: PkFactory;
7586
/** A document specifying configuration options for timeseries collections. */
7687
timeseries?: TimeSeriesCollectionOptions;
77-
/** The number of seconds after which a document in a timeseries collection expires. */
88+
/** A document specifying configuration options for clustered collections. For MongoDB 5.3 and above. */
89+
clusteredIndex?: ClusteredCollectionOptions;
90+
/** The number of seconds after which a document in a timeseries or clustered collection expires. */
7891
expireAfterSeconds?: number;
7992
/** @experimental */
8093
encryptedFields?: Document;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"description": "clustered-indexes",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "5.3"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0"
13+
}
14+
},
15+
{
16+
"database": {
17+
"id": "database0",
18+
"client": "client0",
19+
"databaseName": "ts-tests"
20+
}
21+
},
22+
{
23+
"collection": {
24+
"id": "collection0",
25+
"database": "database0",
26+
"collectionName": "test"
27+
}
28+
}
29+
],
30+
"initialData": [
31+
{
32+
"collectionName": "test",
33+
"databaseName": "ts-tests",
34+
"documents": []
35+
}
36+
],
37+
"tests": [
38+
{
39+
"description": "createCollection with clusteredIndex",
40+
"operations": [
41+
{
42+
"name": "dropCollection",
43+
"object": "database0",
44+
"arguments": {
45+
"collection": "test"
46+
}
47+
},
48+
{
49+
"name": "createCollection",
50+
"object": "database0",
51+
"arguments": {
52+
"collection": "test",
53+
"clusteredIndex": {
54+
"key": {
55+
"_id": 1
56+
},
57+
"unique": true,
58+
"name": "test index"
59+
}
60+
}
61+
},
62+
{
63+
"name": "assertCollectionExists",
64+
"object": "testRunner",
65+
"arguments": {
66+
"databaseName": "ts-tests",
67+
"collectionName": "test"
68+
}
69+
}
70+
]
71+
},
72+
{
73+
"description": "listCollections includes clusteredIndex",
74+
"operations": [
75+
{
76+
"name": "dropCollection",
77+
"object": "database0",
78+
"arguments": {
79+
"collection": "test"
80+
}
81+
},
82+
{
83+
"name": "createCollection",
84+
"object": "database0",
85+
"arguments": {
86+
"collection": "test",
87+
"clusteredIndex": {
88+
"key": {
89+
"_id": 1
90+
},
91+
"unique": true,
92+
"name": "test index"
93+
}
94+
}
95+
},
96+
{
97+
"name": "listCollections",
98+
"object": "database0",
99+
"arguments": {
100+
"filter": {
101+
"name": {
102+
"$eq": "test"
103+
}
104+
}
105+
},
106+
"expectResult": [
107+
{
108+
"name": "test",
109+
"options": {
110+
"clusteredIndex": {
111+
"key": {
112+
"_id": 1
113+
},
114+
"unique": true,
115+
"name": "test index",
116+
"v": {
117+
"$$type": [
118+
"int",
119+
"long"
120+
]
121+
}
122+
}
123+
}
124+
}
125+
]
126+
}
127+
]
128+
},
129+
{
130+
"description": "listIndexes returns the index",
131+
"operations": [
132+
{
133+
"name": "dropCollection",
134+
"object": "database0",
135+
"arguments": {
136+
"collection": "test"
137+
}
138+
},
139+
{
140+
"name": "createCollection",
141+
"object": "database0",
142+
"arguments": {
143+
"collection": "test",
144+
"clusteredIndex": {
145+
"key": {
146+
"_id": 1
147+
},
148+
"unique": true,
149+
"name": "test index"
150+
}
151+
}
152+
},
153+
{
154+
"name": "listIndexes",
155+
"object": "collection0",
156+
"expectResult": [
157+
{
158+
"key": {
159+
"_id": 1
160+
},
161+
"name": "test index",
162+
"clustered": true,
163+
"unique": true,
164+
"v": {
165+
"$$type": [
166+
"int",
167+
"long"
168+
]
169+
}
170+
}
171+
]
172+
}
173+
]
174+
}
175+
]
176+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
description: "clustered-indexes"
2+
3+
schemaVersion: "1.0"
4+
5+
runOnRequirements:
6+
- minServerVersion: "5.3"
7+
8+
createEntities:
9+
- client:
10+
id: &client0 client0
11+
- database:
12+
id: &database0 database0
13+
client: *client0
14+
databaseName: &database0Name ts-tests
15+
- collection:
16+
id: &collection0 collection0
17+
database: *database0
18+
collectionName: &collection0Name test
19+
20+
initialData:
21+
- collectionName: *collection0Name
22+
databaseName: *database0Name
23+
documents: []
24+
25+
tests:
26+
- description: "createCollection with clusteredIndex"
27+
operations:
28+
- name: dropCollection
29+
object: *database0
30+
arguments:
31+
collection: *collection0Name
32+
- name: createCollection
33+
object: *database0
34+
arguments:
35+
collection: *collection0Name
36+
clusteredIndex:
37+
key: { _id: 1 }
38+
unique: true
39+
name: &index0Name "test index"
40+
- name: assertCollectionExists
41+
object: testRunner
42+
arguments:
43+
databaseName: *database0Name
44+
collectionName: *collection0Name
45+
46+
- description: "listCollections includes clusteredIndex"
47+
operations:
48+
- name: dropCollection
49+
object: *database0
50+
arguments:
51+
collection: *collection0Name
52+
- name: createCollection
53+
object: *database0
54+
arguments:
55+
collection: *collection0Name
56+
clusteredIndex:
57+
key: { _id: 1 }
58+
unique: true
59+
name: &index0Name "test index"
60+
- name: listCollections
61+
object: *database0
62+
arguments:
63+
filter: { name: { $eq: *collection0Name } }
64+
expectResult:
65+
- name: *collection0Name
66+
options:
67+
clusteredIndex:
68+
key: { _id: 1 }
69+
unique: true
70+
name: *index0Name
71+
v: { $$type: [ int, long ] }
72+
73+
- description: "listIndexes returns the index"
74+
operations:
75+
- name: dropCollection
76+
object: *database0
77+
arguments:
78+
collection: *collection0Name
79+
- name: createCollection
80+
object: *database0
81+
arguments:
82+
collection: *collection0Name
83+
clusteredIndex:
84+
key: { _id: 1 }
85+
unique: true
86+
name: *index0Name
87+
- name: listIndexes
88+
object: *collection0
89+
expectResult:
90+
- key: { _id: 1 }
91+
name: *index0Name
92+
clustered: true
93+
unique: true
94+
v: { $$type: [ int, long ] }

0 commit comments

Comments
 (0)