mongodb 6.5.0 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/lib/admin.js +9 -9
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +33 -22
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +13 -12
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +28 -18
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +6 -6
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/aws.js +13 -10
- package/lib/client-side-encryption/providers/aws.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +6 -3
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +140 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +7 -6
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +8 -101
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/scram.js +2 -2
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/commands.js +24 -111
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +4 -4
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +61 -36
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +22 -13
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +2 -2
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +8 -8
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js +218 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +184 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/collection.js +42 -38
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +4 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +76 -43
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +16 -33
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +36 -18
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +3 -2
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +15 -19
- package/lib/db.js.map +1 -1
- package/lib/deps.js +31 -26
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +14 -5
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +4 -3
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +19 -14
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +6 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +11 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +3 -0
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +2 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +4 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -8
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +4 -4
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +2 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +29 -121
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +3 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/run_command.js +4 -2
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/search_indexes/create.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/monitor.js +139 -42
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +5 -15
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -0
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +1 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +67 -54
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +10 -0
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +133 -93
- package/lib/sessions.js.map +1 -1
- package/lib/timeout.js +77 -0
- package/lib/timeout.js.map +1 -0
- package/lib/utils.js +61 -28
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +150 -38
- package/package.json +16 -13
- package/src/admin.ts +9 -9
- package/src/bson.ts +14 -0
- package/src/bulk/common.ts +3 -2
- package/src/change_stream.ts +39 -30
- package/src/client-side-encryption/auto_encrypter.ts +2 -2
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/aws.ts +17 -10
- package/src/client-side-encryption/providers/azure.ts +5 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +169 -0
- package/src/cmap/auth/gssapi.ts +9 -11
- package/src/cmap/auth/mongodb_aws.ts +19 -126
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
- package/src/cmap/auth/scram.ts +2 -2
- package/src/cmap/commands.ts +28 -132
- package/src/cmap/connect.ts +4 -4
- package/src/cmap/connection.ts +107 -43
- package/src/cmap/connection_pool.ts +32 -29
- package/src/cmap/handshake/client_metadata.ts +2 -5
- package/src/cmap/wire_protocol/compression.ts +11 -13
- package/src/cmap/wire_protocol/on_demand/document.ts +338 -0
- package/src/cmap/wire_protocol/responses.ts +237 -0
- package/src/collection.ts +87 -58
- package/src/connection_string.ts +9 -7
- package/src/cursor/abstract_cursor.ts +102 -38
- package/src/cursor/aggregation_cursor.ts +32 -34
- package/src/cursor/find_cursor.ts +33 -21
- package/src/cursor/list_search_indexes_cursor.ts +1 -1
- package/src/cursor/run_command_cursor.ts +3 -2
- package/src/db.ts +42 -21
- package/src/deps.ts +52 -40
- package/src/encrypter.ts +14 -5
- package/src/error.ts +9 -3
- package/src/gridfs/download.ts +19 -31
- package/src/gridfs/index.ts +2 -0
- package/src/gridfs/upload.ts +11 -8
- package/src/index.ts +13 -5
- package/src/mongo_client.ts +21 -15
- package/src/mongo_logger.ts +3 -0
- package/src/mongo_types.ts +1 -1
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/command.ts +1 -1
- package/src/operations/create_collection.ts +7 -2
- package/src/operations/delete.ts +4 -3
- package/src/operations/drop.ts +1 -1
- package/src/operations/execute_operation.ts +29 -10
- package/src/operations/find.ts +13 -14
- package/src/operations/get_more.ts +9 -1
- package/src/operations/indexes.ts +103 -176
- package/src/operations/insert.ts +2 -2
- package/src/operations/kill_cursors.ts +3 -2
- package/src/operations/list_collections.ts +5 -1
- package/src/operations/list_databases.ts +1 -1
- package/src/operations/operation.ts +3 -0
- package/src/operations/run_command.ts +6 -4
- package/src/operations/search_indexes/create.ts +4 -1
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +7 -7
- package/src/sdam/common.ts +8 -2
- package/src/sdam/monitor.ts +178 -61
- package/src/sdam/server.ts +27 -20
- package/src/sdam/server_description.ts +8 -3
- package/src/sdam/server_selection.ts +2 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +114 -117
- package/src/sdam/topology_description.ts +14 -4
- package/src/sessions.ts +168 -148
- package/src/timeout.ts +96 -0
- package/src/utils.ts +85 -32
- package/lib/operations/common_functions.js +0 -38
- package/lib/operations/common_functions.js.map +0 -1
- package/src/operations/common_functions.ts +0 -79
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
2
|
import type { Collection } from '../collection';
|
|
3
|
-
import type
|
|
4
|
-
import { MongoCompatibilityError
|
|
3
|
+
import { type AbstractCursorOptions } from '../cursor/abstract_cursor';
|
|
4
|
+
import { MongoCompatibilityError } from '../error';
|
|
5
5
|
import { type OneOrMore } from '../mongo_types';
|
|
6
|
-
import { ReadPreference } from '../read_preference';
|
|
7
6
|
import type { Server } from '../sdam/server';
|
|
8
7
|
import type { ClientSession } from '../sessions';
|
|
9
8
|
import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
@@ -13,8 +12,7 @@ import {
|
|
|
13
12
|
type CommandOperationOptions,
|
|
14
13
|
type OperationParent
|
|
15
14
|
} from './command';
|
|
16
|
-
import {
|
|
17
|
-
import { AbstractOperation, Aspect, defineAspects } from './operation';
|
|
15
|
+
import { Aspect, defineAspects } from './operation';
|
|
18
16
|
|
|
19
17
|
const VALID_INDEX_OPTIONS = new Set([
|
|
20
18
|
'background',
|
|
@@ -73,6 +71,29 @@ export type IndexSpecification = OneOrMore<
|
|
|
73
71
|
| Map<string, IndexDirection>
|
|
74
72
|
>;
|
|
75
73
|
|
|
74
|
+
/** @public */
|
|
75
|
+
export interface IndexInformationOptions extends ListIndexesOptions {
|
|
76
|
+
/**
|
|
77
|
+
* When `true`, an array of index descriptions is returned.
|
|
78
|
+
* When `false`, the driver returns an object that with keys corresponding to index names with values
|
|
79
|
+
* corresponding to the entries of the indexes' key.
|
|
80
|
+
*
|
|
81
|
+
* For example, the given the following indexes:
|
|
82
|
+
* ```
|
|
83
|
+
* [ { name: 'a_1', key: { a: 1 } }, { name: 'b_1_c_1' , key: { b: 1, c: 1 } }]
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* When `full` is `true`, the above array is returned. When `full` is `false`, the following is returned:
|
|
87
|
+
* ```
|
|
88
|
+
* {
|
|
89
|
+
* 'a_1': [['a', 1]],
|
|
90
|
+
* 'b_1_c_1': [['b', 1], ['c', 1]],
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
full?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
76
97
|
/** @public */
|
|
77
98
|
export interface IndexDescription
|
|
78
99
|
extends Pick<
|
|
@@ -146,10 +167,11 @@ function isSingleIndexTuple(t: unknown): t is [string, IndexDirection] {
|
|
|
146
167
|
return Array.isArray(t) && t.length === 2 && isIndexDirection(t[1]);
|
|
147
168
|
}
|
|
148
169
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Converts an `IndexSpecification`, which can be specified in multiple formats, into a
|
|
172
|
+
* valid `key` for the createIndexes command.
|
|
173
|
+
*/
|
|
174
|
+
function constructIndexDescriptionMap(indexSpec: IndexSpecification): Map<string, IndexDirection> {
|
|
153
175
|
const key: Map<string, IndexDirection> = new Map();
|
|
154
176
|
|
|
155
177
|
const indexSpecs =
|
|
@@ -172,46 +194,60 @@ function makeIndexSpec(
|
|
|
172
194
|
}
|
|
173
195
|
}
|
|
174
196
|
|
|
175
|
-
return
|
|
197
|
+
return key;
|
|
176
198
|
}
|
|
177
199
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
200
|
+
/**
|
|
201
|
+
* Receives an index description and returns a modified index description which has had invalid options removed
|
|
202
|
+
* from the description and has mapped the `version` option to the `v` option.
|
|
203
|
+
*/
|
|
204
|
+
function resolveIndexDescription(
|
|
205
|
+
description: IndexDescription
|
|
206
|
+
): Omit<ResolvedIndexDescription, 'key'> {
|
|
207
|
+
const validProvidedOptions = Object.entries(description).filter(([optionName]) =>
|
|
208
|
+
VALID_INDEX_OPTIONS.has(optionName)
|
|
209
|
+
);
|
|
188
210
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
return Object.fromEntries(
|
|
212
|
+
// we support the `version` option, but the `createIndexes` command expects it to be the `v`
|
|
213
|
+
validProvidedOptions.map(([name, value]) => (name === 'version' ? ['v', value] : [name, value]))
|
|
214
|
+
);
|
|
215
|
+
}
|
|
192
216
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
217
|
+
/**
|
|
218
|
+
* @public
|
|
219
|
+
* The index information returned by the listIndexes command. https://www.mongodb.com/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes
|
|
220
|
+
*/
|
|
221
|
+
export type IndexDescriptionInfo = Omit<IndexDescription, 'key' | 'version'> & {
|
|
222
|
+
key: { [key: string]: IndexDirection };
|
|
223
|
+
v?: IndexDescription['version'];
|
|
224
|
+
} & Document;
|
|
196
225
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
226
|
+
/** @public */
|
|
227
|
+
export type IndexDescriptionCompact = Record<string, [name: string, direction: IndexDirection][]>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @internal
|
|
231
|
+
*
|
|
232
|
+
* Internally, the driver represents index description keys with `Map`s to preserve key ordering.
|
|
233
|
+
* We don't require users to specify maps, so we transform user provided descriptions into
|
|
234
|
+
* "resolved" by converting the `key` into a JS `Map`, if it isn't already a map.
|
|
235
|
+
*
|
|
236
|
+
* Additionally, we support the `version` option, but the `createIndexes` command uses the field `v`
|
|
237
|
+
* to specify the index version so we map the value of `version` to `v`, if provided.
|
|
238
|
+
*/
|
|
239
|
+
type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
|
|
240
|
+
key: Map<string, IndexDirection>;
|
|
241
|
+
v?: IndexDescription['version'];
|
|
242
|
+
};
|
|
205
243
|
|
|
206
244
|
/** @internal */
|
|
207
|
-
export class CreateIndexesOperation<
|
|
208
|
-
T extends string | string[] = string[]
|
|
209
|
-
> extends CommandOperation<T> {
|
|
245
|
+
export class CreateIndexesOperation extends CommandOperation<string[]> {
|
|
210
246
|
override options: CreateIndexesOptions;
|
|
211
247
|
collectionName: string;
|
|
212
|
-
indexes: ReadonlyArray<
|
|
248
|
+
indexes: ReadonlyArray<ResolvedIndexDescription>;
|
|
213
249
|
|
|
214
|
-
constructor(
|
|
250
|
+
private constructor(
|
|
215
251
|
parent: OperationParent,
|
|
216
252
|
collectionName: string,
|
|
217
253
|
indexes: IndexDescription[],
|
|
@@ -221,16 +257,12 @@ export class CreateIndexesOperation<
|
|
|
221
257
|
|
|
222
258
|
this.options = options ?? {};
|
|
223
259
|
this.collectionName = collectionName;
|
|
224
|
-
this.indexes = indexes.map(userIndex => {
|
|
260
|
+
this.indexes = indexes.map((userIndex: IndexDescription): ResolvedIndexDescription => {
|
|
225
261
|
// Ensure the key is a Map to preserve index key ordering
|
|
226
262
|
const key =
|
|
227
263
|
userIndex.key instanceof Map ? userIndex.key : new Map(Object.entries(userIndex.key));
|
|
228
|
-
const name = userIndex.name
|
|
229
|
-
const validIndexOptions =
|
|
230
|
-
Object.entries({ ...userIndex }).filter(([optionName]) =>
|
|
231
|
-
VALID_INDEX_OPTIONS.has(optionName)
|
|
232
|
-
)
|
|
233
|
-
);
|
|
264
|
+
const name = userIndex.name ?? Array.from(key).flat().join('_');
|
|
265
|
+
const validIndexOptions = resolveIndexDescription(userIndex);
|
|
234
266
|
return {
|
|
235
267
|
...validIndexOptions,
|
|
236
268
|
name,
|
|
@@ -239,11 +271,31 @@ export class CreateIndexesOperation<
|
|
|
239
271
|
});
|
|
240
272
|
}
|
|
241
273
|
|
|
274
|
+
static fromIndexDescriptionArray(
|
|
275
|
+
parent: OperationParent,
|
|
276
|
+
collectionName: string,
|
|
277
|
+
indexes: IndexDescription[],
|
|
278
|
+
options?: CreateIndexesOptions
|
|
279
|
+
): CreateIndexesOperation {
|
|
280
|
+
return new CreateIndexesOperation(parent, collectionName, indexes, options);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
static fromIndexSpecification(
|
|
284
|
+
parent: OperationParent,
|
|
285
|
+
collectionName: string,
|
|
286
|
+
indexSpec: IndexSpecification,
|
|
287
|
+
options: CreateIndexesOptions = {}
|
|
288
|
+
): CreateIndexesOperation {
|
|
289
|
+
const key = constructIndexDescriptionMap(indexSpec);
|
|
290
|
+
const description: IndexDescription = { ...options, key };
|
|
291
|
+
return new CreateIndexesOperation(parent, collectionName, [description], options);
|
|
292
|
+
}
|
|
293
|
+
|
|
242
294
|
override get commandName() {
|
|
243
295
|
return 'createIndexes';
|
|
244
296
|
}
|
|
245
297
|
|
|
246
|
-
override async execute(server: Server, session: ClientSession | undefined): Promise<
|
|
298
|
+
override async execute(server: Server, session: ClientSession | undefined): Promise<string[]> {
|
|
247
299
|
const options = this.options;
|
|
248
300
|
const indexes = this.indexes;
|
|
249
301
|
|
|
@@ -266,61 +318,7 @@ export class CreateIndexesOperation<
|
|
|
266
318
|
await super.executeCommand(server, session, cmd);
|
|
267
319
|
|
|
268
320
|
const indexNames = indexes.map(index => index.name || '');
|
|
269
|
-
return indexNames
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/** @internal */
|
|
274
|
-
export class CreateIndexOperation extends CreateIndexesOperation<string> {
|
|
275
|
-
constructor(
|
|
276
|
-
parent: OperationParent,
|
|
277
|
-
collectionName: string,
|
|
278
|
-
indexSpec: IndexSpecification,
|
|
279
|
-
options?: CreateIndexesOptions
|
|
280
|
-
) {
|
|
281
|
-
super(parent, collectionName, [makeIndexSpec(indexSpec, options)], options);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
override async execute(server: Server, session: ClientSession | undefined): Promise<string> {
|
|
285
|
-
const indexNames = await super.execute(server, session);
|
|
286
|
-
return indexNames[0];
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/** @internal */
|
|
291
|
-
export class EnsureIndexOperation extends CreateIndexOperation {
|
|
292
|
-
db: Db;
|
|
293
|
-
|
|
294
|
-
constructor(
|
|
295
|
-
db: Db,
|
|
296
|
-
collectionName: string,
|
|
297
|
-
indexSpec: IndexSpecification,
|
|
298
|
-
options?: CreateIndexesOptions
|
|
299
|
-
) {
|
|
300
|
-
super(db, collectionName, indexSpec, options);
|
|
301
|
-
|
|
302
|
-
this.readPreference = ReadPreference.primary;
|
|
303
|
-
this.db = db;
|
|
304
|
-
this.collectionName = collectionName;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
override get commandName() {
|
|
308
|
-
return 'listIndexes';
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
override async execute(server: Server, session: ClientSession | undefined): Promise<string> {
|
|
312
|
-
const indexName = this.indexes[0].name;
|
|
313
|
-
const indexes = await this.db
|
|
314
|
-
.collection(this.collectionName)
|
|
315
|
-
.listIndexes({ session })
|
|
316
|
-
.toArray()
|
|
317
|
-
.catch(error => {
|
|
318
|
-
if (error instanceof MongoError && error.code === MONGODB_ERROR_CODES.NamespaceNotFound)
|
|
319
|
-
return [];
|
|
320
|
-
throw error;
|
|
321
|
-
});
|
|
322
|
-
if (indexName && indexes.some(index => index.name === indexName)) return indexName;
|
|
323
|
-
return super.execute(server, session);
|
|
321
|
+
return indexNames;
|
|
324
322
|
}
|
|
325
323
|
}
|
|
326
324
|
|
|
@@ -347,15 +345,12 @@ export class DropIndexOperation extends CommandOperation<Document> {
|
|
|
347
345
|
|
|
348
346
|
override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
|
|
349
347
|
const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName };
|
|
350
|
-
return super.executeCommand(server, session, cmd);
|
|
348
|
+
return await super.executeCommand(server, session, cmd);
|
|
351
349
|
}
|
|
352
350
|
}
|
|
353
351
|
|
|
354
352
|
/** @public */
|
|
355
|
-
export
|
|
356
|
-
/** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
|
|
357
|
-
batchSize?: number;
|
|
358
|
-
}
|
|
353
|
+
export type ListIndexesOptions = AbstractCursorOptions;
|
|
359
354
|
|
|
360
355
|
/** @internal */
|
|
361
356
|
export class ListIndexesOperation extends CommandOperation<Document> {
|
|
@@ -394,73 +389,7 @@ export class ListIndexesOperation extends CommandOperation<Document> {
|
|
|
394
389
|
command.comment = this.options.comment;
|
|
395
390
|
}
|
|
396
391
|
|
|
397
|
-
return super.executeCommand(server, session, command);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/** @internal */
|
|
402
|
-
export class IndexExistsOperation extends AbstractOperation<boolean> {
|
|
403
|
-
override options: IndexInformationOptions;
|
|
404
|
-
collection: Collection;
|
|
405
|
-
indexes: string | string[];
|
|
406
|
-
|
|
407
|
-
constructor(
|
|
408
|
-
collection: Collection,
|
|
409
|
-
indexes: string | string[],
|
|
410
|
-
options: IndexInformationOptions
|
|
411
|
-
) {
|
|
412
|
-
super(options);
|
|
413
|
-
this.options = options;
|
|
414
|
-
this.collection = collection;
|
|
415
|
-
this.indexes = indexes;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
override get commandName() {
|
|
419
|
-
return 'listIndexes' as const;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
override async execute(server: Server, session: ClientSession | undefined): Promise<boolean> {
|
|
423
|
-
const coll = this.collection;
|
|
424
|
-
const indexes = this.indexes;
|
|
425
|
-
|
|
426
|
-
const info = await indexInformation(coll.s.db, coll.collectionName, {
|
|
427
|
-
...this.options,
|
|
428
|
-
readPreference: this.readPreference,
|
|
429
|
-
session
|
|
430
|
-
});
|
|
431
|
-
// Let's check for the index names
|
|
432
|
-
if (!Array.isArray(indexes)) return info[indexes] != null;
|
|
433
|
-
// All keys found return true
|
|
434
|
-
return indexes.every(indexName => info[indexName] != null);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/** @internal */
|
|
439
|
-
export class IndexInformationOperation extends AbstractOperation<Document> {
|
|
440
|
-
override options: IndexInformationOptions;
|
|
441
|
-
db: Db;
|
|
442
|
-
name: string;
|
|
443
|
-
|
|
444
|
-
constructor(db: Db, name: string, options?: IndexInformationOptions) {
|
|
445
|
-
super(options);
|
|
446
|
-
this.options = options ?? {};
|
|
447
|
-
this.db = db;
|
|
448
|
-
this.name = name;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
override get commandName() {
|
|
452
|
-
return 'listIndexes' as const;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
|
|
456
|
-
const db = this.db;
|
|
457
|
-
const name = this.name;
|
|
458
|
-
|
|
459
|
-
return indexInformation(db, name, {
|
|
460
|
-
...this.options,
|
|
461
|
-
readPreference: this.readPreference,
|
|
462
|
-
session
|
|
463
|
-
});
|
|
392
|
+
return await super.executeCommand(server, session, command);
|
|
464
393
|
}
|
|
465
394
|
}
|
|
466
395
|
|
|
@@ -470,6 +399,4 @@ defineAspects(ListIndexesOperation, [
|
|
|
470
399
|
Aspect.CURSOR_CREATING
|
|
471
400
|
]);
|
|
472
401
|
defineAspects(CreateIndexesOperation, [Aspect.WRITE_OPERATION]);
|
|
473
|
-
defineAspects(CreateIndexOperation, [Aspect.WRITE_OPERATION]);
|
|
474
|
-
defineAspects(EnsureIndexOperation, [Aspect.WRITE_OPERATION]);
|
|
475
402
|
defineAspects(DropIndexOperation, [Aspect.WRITE_OPERATION]);
|
package/src/operations/insert.ts
CHANGED
|
@@ -6,10 +6,10 @@ import type { InferIdType } from '../mongo_types';
|
|
|
6
6
|
import type { Server } from '../sdam/server';
|
|
7
7
|
import type { ClientSession } from '../sessions';
|
|
8
8
|
import type { MongoDBNamespace } from '../utils';
|
|
9
|
+
import { maybeAddIdToDocuments } from '../utils';
|
|
9
10
|
import { WriteConcern } from '../write_concern';
|
|
10
11
|
import { BulkWriteOperation } from './bulk_write';
|
|
11
12
|
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
12
|
-
import { maybeAddIdToDocuments } from './common_functions';
|
|
13
13
|
import { AbstractOperation, Aspect, defineAspects } from './operation';
|
|
14
14
|
|
|
15
15
|
/** @internal */
|
|
@@ -47,7 +47,7 @@ export class InsertOperation extends CommandOperation<Document> {
|
|
|
47
47
|
command.comment = options.comment;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
return super.executeCommand(server, session, command);
|
|
50
|
+
return await super.executeCommand(server, session, command);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -2,7 +2,7 @@ import type { Long } from '../bson';
|
|
|
2
2
|
import { MongoRuntimeError } from '../error';
|
|
3
3
|
import type { Server } from '../sdam/server';
|
|
4
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
-
import type
|
|
5
|
+
import { type MongoDBNamespace, squashError } from '../utils';
|
|
6
6
|
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -47,8 +47,9 @@ export class KillCursorsOperation extends AbstractOperation {
|
|
|
47
47
|
};
|
|
48
48
|
try {
|
|
49
49
|
await server.command(this.ns, killCursorsCommand, { session });
|
|
50
|
-
} catch {
|
|
50
|
+
} catch (error) {
|
|
51
51
|
// The driver should never emit errors from killCursors, this is spec-ed behavior
|
|
52
|
+
squashError(error);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
@@ -52,7 +52,11 @@ export class ListCollectionsOperation extends CommandOperation<Document> {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
|
|
55
|
-
return super.executeCommand(
|
|
55
|
+
return await super.executeCommand(
|
|
56
|
+
server,
|
|
57
|
+
session,
|
|
58
|
+
this.generateCommand(maxWireVersion(server))
|
|
59
|
+
);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/* This is here for the purpose of unit testing the final command that gets sent. */
|
|
@@ -63,7 +63,7 @@ export class ListDatabasesOperation extends CommandOperation<ListDatabasesResult
|
|
|
63
63
|
cmd.comment = this.options.comment;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
return super.executeCommand(server, session, cmd) as TODO_NODE_3286;
|
|
66
|
+
return await (super.executeCommand(server, session, cmd) as Promise<TODO_NODE_3286>);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -34,6 +34,9 @@ export interface OperationOptions extends BSONSerializeOptions {
|
|
|
34
34
|
/** @internal Hints to `executeOperation` that this operation should not unpin on an ended transaction */
|
|
35
35
|
bypassPinningCheck?: boolean;
|
|
36
36
|
omitReadPreference?: boolean;
|
|
37
|
+
|
|
38
|
+
/** @internal TODO(NODE-5688): make this public */
|
|
39
|
+
timeoutMS?: number;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
/** @internal */
|
|
@@ -28,11 +28,12 @@ export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
|
|
|
28
28
|
|
|
29
29
|
override async execute(server: Server, session: ClientSession | undefined): Promise<T> {
|
|
30
30
|
this.server = server;
|
|
31
|
-
|
|
31
|
+
const res: TODO_NODE_3286 = await server.command(this.ns, this.command, {
|
|
32
32
|
...this.options,
|
|
33
33
|
readPreference: this.readPreference,
|
|
34
34
|
session
|
|
35
|
-
})
|
|
35
|
+
});
|
|
36
|
+
return res;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -54,10 +55,11 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
|
|
|
54
55
|
|
|
55
56
|
override async execute(server: Server, session: ClientSession | undefined): Promise<T> {
|
|
56
57
|
this.server = server;
|
|
57
|
-
|
|
58
|
+
const res: TODO_NODE_3286 = await server.command(this.ns, this.command, {
|
|
58
59
|
...this.options,
|
|
59
60
|
readPreference: this.readPreference,
|
|
60
61
|
session
|
|
61
|
-
})
|
|
62
|
+
});
|
|
63
|
+
return res;
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -8,12 +8,15 @@ import { AbstractOperation } from '../operation';
|
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
export interface SearchIndexDescription {
|
|
11
|
+
export interface SearchIndexDescription extends Document {
|
|
12
12
|
/** The name of the index. */
|
|
13
13
|
name?: string;
|
|
14
14
|
|
|
15
15
|
/** The index definition. */
|
|
16
16
|
definition: Document;
|
|
17
|
+
|
|
18
|
+
/** The type of the index. Currently `search` or `vectorSearch` are supported. */
|
|
19
|
+
type?: string;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
/** @internal */
|
package/src/operations/stats.ts
CHANGED
package/src/operations/update.ts
CHANGED
|
@@ -122,7 +122,7 @@ export class UpdateOperation extends CommandOperation<Document> {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
return super.executeCommand(server, session, command);
|
|
125
|
+
return await super.executeCommand(server, session, command);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -144,8 +144,8 @@ export class UpdateOneOperation extends UpdateOperation {
|
|
|
144
144
|
server: Server,
|
|
145
145
|
session: ClientSession | undefined
|
|
146
146
|
): Promise<UpdateResult> {
|
|
147
|
-
const res = await super.execute(server, session);
|
|
148
|
-
if (this.explain != null) return res
|
|
147
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
148
|
+
if (this.explain != null) return res;
|
|
149
149
|
if (res.code) throw new MongoServerError(res);
|
|
150
150
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
151
151
|
|
|
@@ -178,8 +178,8 @@ export class UpdateManyOperation extends UpdateOperation {
|
|
|
178
178
|
server: Server,
|
|
179
179
|
session: ClientSession | undefined
|
|
180
180
|
): Promise<UpdateResult> {
|
|
181
|
-
const res = await super.execute(server, session);
|
|
182
|
-
if (this.explain != null) return res
|
|
181
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
182
|
+
if (this.explain != null) return res;
|
|
183
183
|
if (res.code) throw new MongoServerError(res);
|
|
184
184
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
185
185
|
|
|
@@ -231,8 +231,8 @@ export class ReplaceOneOperation extends UpdateOperation {
|
|
|
231
231
|
server: Server,
|
|
232
232
|
session: ClientSession | undefined
|
|
233
233
|
): Promise<UpdateResult> {
|
|
234
|
-
const res = await super.execute(server, session);
|
|
235
|
-
if (this.explain != null) return res
|
|
234
|
+
const res: TODO_NODE_3286 = await super.execute(server, session);
|
|
235
|
+
if (this.explain != null) return res;
|
|
236
236
|
if (res.code) throw new MongoServerError(res);
|
|
237
237
|
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
238
238
|
|
package/src/sdam/common.ts
CHANGED
|
@@ -55,10 +55,16 @@ export function drainTimerQueue(queue: TimerQueue): void {
|
|
|
55
55
|
queue.clear();
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
* Gossiped in component for the cluster time tracking the state of user databases
|
|
61
|
+
* across the cluster. It may optionally include a signature identifying the process that
|
|
62
|
+
* generated such a value.
|
|
63
|
+
*/
|
|
59
64
|
export interface ClusterTime {
|
|
60
65
|
clusterTime: Timestamp;
|
|
61
|
-
|
|
66
|
+
/** Used to validate the identity of a request or response's ClusterTime. */
|
|
67
|
+
signature?: {
|
|
62
68
|
hash: Binary;
|
|
63
69
|
keyId: Long;
|
|
64
70
|
};
|