mongodb 6.9.0-dev.20241018.sha.a7d1d43e → 6.9.0-dev.20241021.sha.30c61f2a
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/lib/beta.d.ts +65 -29
- package/lib/bson.js +1 -0
- package/lib/bson.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
- package/lib/cmap/wire_protocol/responses.js.map +1 -1
- package/lib/cursor/client_bulk_write_cursor.js.map +1 -1
- package/lib/mongo_client.js +2 -1
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -1
- package/lib/operations/client_bulk_write/executor.js +4 -4
- package/lib/operations/client_bulk_write/executor.js.map +1 -1
- package/lib/operations/client_bulk_write/results_merger.js +37 -0
- package/lib/operations/client_bulk_write/results_merger.js.map +1 -1
- package/lib/operations/search_indexes/create.js.map +1 -1
- package/lib/operations/search_indexes/drop.js.map +1 -1
- package/lib/operations/search_indexes/update.js.map +1 -1
- package/mongodb.d.ts +65 -29
- package/package.json +1 -1
- package/src/beta.ts +1 -1
- package/src/bson.ts +3 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +1 -2
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +1 -2
- package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc.ts +1 -2
- package/src/cmap/connection.ts +7 -2
- package/src/cmap/wire_protocol/on_demand/document.ts +1 -2
- package/src/cmap/wire_protocol/responses.ts +1 -2
- package/src/cursor/client_bulk_write_cursor.ts +1 -2
- package/src/index.ts +1 -0
- package/src/mongo_client.ts +10 -6
- package/src/mongo_types.ts +2 -1
- package/src/operations/client_bulk_write/command_builder.ts +17 -11
- package/src/operations/client_bulk_write/common.ts +71 -31
- package/src/operations/client_bulk_write/executor.ts +11 -9
- package/src/operations/client_bulk_write/results_merger.ts +82 -3
- package/src/operations/search_indexes/create.ts +1 -2
- package/src/operations/search_indexes/drop.ts +1 -2
- package/src/operations/search_indexes/update.ts +1 -2
|
@@ -36,7 +36,7 @@ const MESSAGE_OVERHEAD_BYTES = 1000;
|
|
|
36
36
|
|
|
37
37
|
/** @internal */
|
|
38
38
|
export class ClientBulkWriteCommandBuilder {
|
|
39
|
-
models: AnyClientBulkWriteModel
|
|
39
|
+
models: ReadonlyArray<AnyClientBulkWriteModel<Document>>;
|
|
40
40
|
options: ClientBulkWriteOptions;
|
|
41
41
|
pkFactory: PkFactory;
|
|
42
42
|
/** The current index in the models array that is being processed. */
|
|
@@ -53,7 +53,7 @@ export class ClientBulkWriteCommandBuilder {
|
|
|
53
53
|
* @param models - The client write models.
|
|
54
54
|
*/
|
|
55
55
|
constructor(
|
|
56
|
-
models: AnyClientBulkWriteModel
|
|
56
|
+
models: ReadonlyArray<AnyClientBulkWriteModel<Document>>,
|
|
57
57
|
options: ClientBulkWriteOptions,
|
|
58
58
|
pkFactory?: PkFactory
|
|
59
59
|
) {
|
|
@@ -248,7 +248,7 @@ interface ClientInsertOperation {
|
|
|
248
248
|
* @returns the operation.
|
|
249
249
|
*/
|
|
250
250
|
export const buildInsertOneOperation = (
|
|
251
|
-
model: ClientInsertOneModel
|
|
251
|
+
model: ClientInsertOneModel<Document>,
|
|
252
252
|
index: number,
|
|
253
253
|
pkFactory: PkFactory
|
|
254
254
|
): ClientInsertOperation => {
|
|
@@ -275,7 +275,10 @@ export interface ClientDeleteOperation {
|
|
|
275
275
|
* @param index - The namespace index.
|
|
276
276
|
* @returns the operation.
|
|
277
277
|
*/
|
|
278
|
-
export const buildDeleteOneOperation = (
|
|
278
|
+
export const buildDeleteOneOperation = (
|
|
279
|
+
model: ClientDeleteOneModel<Document>,
|
|
280
|
+
index: number
|
|
281
|
+
): Document => {
|
|
279
282
|
return createDeleteOperation(model, index, false);
|
|
280
283
|
};
|
|
281
284
|
|
|
@@ -285,7 +288,10 @@ export const buildDeleteOneOperation = (model: ClientDeleteOneModel, index: numb
|
|
|
285
288
|
* @param index - The namespace index.
|
|
286
289
|
* @returns the operation.
|
|
287
290
|
*/
|
|
288
|
-
export const buildDeleteManyOperation = (
|
|
291
|
+
export const buildDeleteManyOperation = (
|
|
292
|
+
model: ClientDeleteManyModel<Document>,
|
|
293
|
+
index: number
|
|
294
|
+
): Document => {
|
|
289
295
|
return createDeleteOperation(model, index, true);
|
|
290
296
|
};
|
|
291
297
|
|
|
@@ -293,7 +299,7 @@ export const buildDeleteManyOperation = (model: ClientDeleteManyModel, index: nu
|
|
|
293
299
|
* Creates a delete operation based on the parameters.
|
|
294
300
|
*/
|
|
295
301
|
function createDeleteOperation(
|
|
296
|
-
model: ClientDeleteOneModel | ClientDeleteManyModel
|
|
302
|
+
model: ClientDeleteOneModel<Document> | ClientDeleteManyModel<Document>,
|
|
297
303
|
index: number,
|
|
298
304
|
multi: boolean
|
|
299
305
|
): ClientDeleteOperation {
|
|
@@ -330,7 +336,7 @@ export interface ClientUpdateOperation {
|
|
|
330
336
|
* @returns the operation.
|
|
331
337
|
*/
|
|
332
338
|
export const buildUpdateOneOperation = (
|
|
333
|
-
model: ClientUpdateOneModel
|
|
339
|
+
model: ClientUpdateOneModel<Document>,
|
|
334
340
|
index: number
|
|
335
341
|
): ClientUpdateOperation => {
|
|
336
342
|
return createUpdateOperation(model, index, false);
|
|
@@ -343,7 +349,7 @@ export const buildUpdateOneOperation = (
|
|
|
343
349
|
* @returns the operation.
|
|
344
350
|
*/
|
|
345
351
|
export const buildUpdateManyOperation = (
|
|
346
|
-
model: ClientUpdateManyModel
|
|
352
|
+
model: ClientUpdateManyModel<Document>,
|
|
347
353
|
index: number
|
|
348
354
|
): ClientUpdateOperation => {
|
|
349
355
|
return createUpdateOperation(model, index, true);
|
|
@@ -365,7 +371,7 @@ function validateUpdate(update: Document) {
|
|
|
365
371
|
* Creates a delete operation based on the parameters.
|
|
366
372
|
*/
|
|
367
373
|
function createUpdateOperation(
|
|
368
|
-
model: ClientUpdateOneModel | ClientUpdateManyModel
|
|
374
|
+
model: ClientUpdateOneModel<Document> | ClientUpdateManyModel<Document>,
|
|
369
375
|
index: number,
|
|
370
376
|
multi: boolean
|
|
371
377
|
): ClientUpdateOperation {
|
|
@@ -413,7 +419,7 @@ export interface ClientReplaceOneOperation {
|
|
|
413
419
|
* @returns the operation.
|
|
414
420
|
*/
|
|
415
421
|
export const buildReplaceOneOperation = (
|
|
416
|
-
model: ClientReplaceOneModel
|
|
422
|
+
model: ClientReplaceOneModel<Document>,
|
|
417
423
|
index: number
|
|
418
424
|
): ClientReplaceOneOperation => {
|
|
419
425
|
if (hasAtomicOperators(model.replacement)) {
|
|
@@ -442,7 +448,7 @@ export const buildReplaceOneOperation = (
|
|
|
442
448
|
|
|
443
449
|
/** @internal */
|
|
444
450
|
export function buildOperation(
|
|
445
|
-
model: AnyClientBulkWriteModel
|
|
451
|
+
model: AnyClientBulkWriteModel<Document>,
|
|
446
452
|
index: number,
|
|
447
453
|
pkFactory: PkFactory
|
|
448
454
|
): Document {
|
|
@@ -27,25 +27,32 @@ export interface ClientBulkWriteOptions extends CommandOperationOptions {
|
|
|
27
27
|
|
|
28
28
|
/** @public */
|
|
29
29
|
export interface ClientWriteModel {
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The namespace for the write.
|
|
32
|
+
*
|
|
33
|
+
* A namespace is a combination of the database name and the name of the collection: `<database-name>.<collection>`.
|
|
34
|
+
* All documents belong to a namespace.
|
|
35
|
+
*
|
|
36
|
+
* @see https://www.mongodb.com/docs/manual/reference/limits/#std-label-faq-dev-namespace
|
|
37
|
+
*/
|
|
31
38
|
namespace: string;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
/** @public */
|
|
35
|
-
export interface ClientInsertOneModel extends ClientWriteModel {
|
|
42
|
+
export interface ClientInsertOneModel<TSchema> extends ClientWriteModel {
|
|
36
43
|
name: 'insertOne';
|
|
37
44
|
/** The document to insert. */
|
|
38
|
-
document: OptionalId<
|
|
45
|
+
document: OptionalId<TSchema>;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
/** @public */
|
|
42
|
-
export interface ClientDeleteOneModel extends ClientWriteModel {
|
|
49
|
+
export interface ClientDeleteOneModel<TSchema> extends ClientWriteModel {
|
|
43
50
|
name: 'deleteOne';
|
|
44
51
|
/**
|
|
45
52
|
* The filter used to determine if a document should be deleted.
|
|
46
53
|
* For a deleteOne operation, the first match is removed.
|
|
47
54
|
*/
|
|
48
|
-
filter: Filter<
|
|
55
|
+
filter: Filter<TSchema>;
|
|
49
56
|
/** Specifies a collation. */
|
|
50
57
|
collation?: CollationOptions;
|
|
51
58
|
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
@@ -53,13 +60,13 @@ export interface ClientDeleteOneModel extends ClientWriteModel {
|
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/** @public */
|
|
56
|
-
export interface ClientDeleteManyModel extends ClientWriteModel {
|
|
63
|
+
export interface ClientDeleteManyModel<TSchema> extends ClientWriteModel {
|
|
57
64
|
name: 'deleteMany';
|
|
58
65
|
/**
|
|
59
66
|
* The filter used to determine if a document should be deleted.
|
|
60
67
|
* For a deleteMany operation, all matches are removed.
|
|
61
68
|
*/
|
|
62
|
-
filter: Filter<
|
|
69
|
+
filter: Filter<TSchema>;
|
|
63
70
|
/** Specifies a collation. */
|
|
64
71
|
collation?: CollationOptions;
|
|
65
72
|
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
@@ -67,15 +74,15 @@ export interface ClientDeleteManyModel extends ClientWriteModel {
|
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
/** @public */
|
|
70
|
-
export interface ClientReplaceOneModel extends ClientWriteModel {
|
|
77
|
+
export interface ClientReplaceOneModel<TSchema> extends ClientWriteModel {
|
|
71
78
|
name: 'replaceOne';
|
|
72
79
|
/**
|
|
73
80
|
* The filter used to determine if a document should be replaced.
|
|
74
81
|
* For a replaceOne operation, the first match is replaced.
|
|
75
82
|
*/
|
|
76
|
-
filter: Filter<
|
|
83
|
+
filter: Filter<TSchema>;
|
|
77
84
|
/** The document with which to replace the matched document. */
|
|
78
|
-
replacement: WithoutId<
|
|
85
|
+
replacement: WithoutId<TSchema>;
|
|
79
86
|
/** Specifies a collation. */
|
|
80
87
|
collation?: CollationOptions;
|
|
81
88
|
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
@@ -85,19 +92,19 @@ export interface ClientReplaceOneModel extends ClientWriteModel {
|
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
/** @public */
|
|
88
|
-
export interface ClientUpdateOneModel extends ClientWriteModel {
|
|
95
|
+
export interface ClientUpdateOneModel<TSchema> extends ClientWriteModel {
|
|
89
96
|
name: 'updateOne';
|
|
90
97
|
/**
|
|
91
98
|
* The filter used to determine if a document should be updated.
|
|
92
99
|
* For an updateOne operation, the first match is updated.
|
|
93
100
|
*/
|
|
94
|
-
filter: Filter<
|
|
101
|
+
filter: Filter<TSchema>;
|
|
95
102
|
/**
|
|
96
103
|
* The modifications to apply. The value can be either:
|
|
97
104
|
* UpdateFilter<Document> - A document that contains update operator expressions,
|
|
98
105
|
* Document[] - an aggregation pipeline.
|
|
99
106
|
*/
|
|
100
|
-
update: UpdateFilter<
|
|
107
|
+
update: UpdateFilter<TSchema> | Document[];
|
|
101
108
|
/** A set of filters specifying to which array elements an update should apply. */
|
|
102
109
|
arrayFilters?: Document[];
|
|
103
110
|
/** Specifies a collation. */
|
|
@@ -109,19 +116,19 @@ export interface ClientUpdateOneModel extends ClientWriteModel {
|
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
/** @public */
|
|
112
|
-
export interface ClientUpdateManyModel extends ClientWriteModel {
|
|
119
|
+
export interface ClientUpdateManyModel<TSchema> extends ClientWriteModel {
|
|
113
120
|
name: 'updateMany';
|
|
114
121
|
/**
|
|
115
122
|
* The filter used to determine if a document should be updated.
|
|
116
123
|
* For an updateMany operation, all matches are updated.
|
|
117
124
|
*/
|
|
118
|
-
filter: Filter<
|
|
125
|
+
filter: Filter<TSchema>;
|
|
119
126
|
/**
|
|
120
127
|
* The modifications to apply. The value can be either:
|
|
121
128
|
* UpdateFilter<Document> - A document that contains update operator expressions,
|
|
122
129
|
* Document[] - an aggregation pipeline.
|
|
123
130
|
*/
|
|
124
|
-
update: UpdateFilter<
|
|
131
|
+
update: UpdateFilter<TSchema> | Document[];
|
|
125
132
|
/** A set of filters specifying to which array elements an update should apply. */
|
|
126
133
|
arrayFilters?: Document[];
|
|
127
134
|
/** Specifies a collation. */
|
|
@@ -137,48 +144,81 @@ export interface ClientUpdateManyModel extends ClientWriteModel {
|
|
|
137
144
|
* to MongoClient#bulkWrite.
|
|
138
145
|
* @public
|
|
139
146
|
*/
|
|
140
|
-
export type AnyClientBulkWriteModel =
|
|
141
|
-
| ClientInsertOneModel
|
|
142
|
-
| ClientReplaceOneModel
|
|
143
|
-
| ClientUpdateOneModel
|
|
144
|
-
| ClientUpdateManyModel
|
|
145
|
-
| ClientDeleteOneModel
|
|
146
|
-
| ClientDeleteManyModel
|
|
147
|
+
export type AnyClientBulkWriteModel<TSchema extends Document> =
|
|
148
|
+
| ClientInsertOneModel<TSchema>
|
|
149
|
+
| ClientReplaceOneModel<TSchema>
|
|
150
|
+
| ClientUpdateOneModel<TSchema>
|
|
151
|
+
| ClientUpdateManyModel<TSchema>
|
|
152
|
+
| ClientDeleteOneModel<TSchema>
|
|
153
|
+
| ClientDeleteManyModel<TSchema>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A mapping of namespace strings to collections schemas.
|
|
157
|
+
* @public
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* type MongoDBSchemas = {
|
|
162
|
+
* 'db.books': Book;
|
|
163
|
+
* 'db.authors': Author;
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* const model: ClientBulkWriteModel<MongoDBSchemas> = {
|
|
167
|
+
* namespace: 'db.books'
|
|
168
|
+
* name: 'insertOne',
|
|
169
|
+
* document: { title: 'Practical MongoDB Aggregations', authorName: 3 } // error `authorName` cannot be number
|
|
170
|
+
* };
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* The type of the `namespace` field narrows other parts of the BulkWriteModel to use the correct schema for type assertions.
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
export type ClientBulkWriteModel<
|
|
177
|
+
SchemaMap extends Record<string, Document> = Record<string, Document>
|
|
178
|
+
> = {
|
|
179
|
+
[Namespace in keyof SchemaMap]: AnyClientBulkWriteModel<SchemaMap[Namespace]> & {
|
|
180
|
+
namespace: Namespace;
|
|
181
|
+
};
|
|
182
|
+
}[keyof SchemaMap];
|
|
147
183
|
|
|
148
184
|
/** @public */
|
|
149
185
|
export interface ClientBulkWriteResult {
|
|
186
|
+
/**
|
|
187
|
+
* Whether the bulk write was acknowledged.
|
|
188
|
+
*/
|
|
189
|
+
readonly acknowledged: boolean;
|
|
150
190
|
/**
|
|
151
191
|
* The total number of documents inserted across all insert operations.
|
|
152
192
|
*/
|
|
153
|
-
insertedCount: number;
|
|
193
|
+
readonly insertedCount: number;
|
|
154
194
|
/**
|
|
155
195
|
* The total number of documents upserted across all update operations.
|
|
156
196
|
*/
|
|
157
|
-
upsertedCount: number;
|
|
197
|
+
readonly upsertedCount: number;
|
|
158
198
|
/**
|
|
159
199
|
* The total number of documents matched across all update operations.
|
|
160
200
|
*/
|
|
161
|
-
matchedCount: number;
|
|
201
|
+
readonly matchedCount: number;
|
|
162
202
|
/**
|
|
163
203
|
* The total number of documents modified across all update operations.
|
|
164
204
|
*/
|
|
165
|
-
modifiedCount: number;
|
|
205
|
+
readonly modifiedCount: number;
|
|
166
206
|
/**
|
|
167
207
|
* The total number of documents deleted across all delete operations.
|
|
168
208
|
*/
|
|
169
|
-
deletedCount: number;
|
|
209
|
+
readonly deletedCount: number;
|
|
170
210
|
/**
|
|
171
211
|
* The results of each individual insert operation that was successfully performed.
|
|
172
212
|
*/
|
|
173
|
-
insertResults?:
|
|
213
|
+
readonly insertResults?: ReadonlyMap<number, ClientInsertOneResult>;
|
|
174
214
|
/**
|
|
175
215
|
* The results of each individual update operation that was successfully performed.
|
|
176
216
|
*/
|
|
177
|
-
updateResults?:
|
|
217
|
+
readonly updateResults?: ReadonlyMap<number, ClientUpdateResult>;
|
|
178
218
|
/**
|
|
179
219
|
* The results of each individual delete operation that was successfully performed.
|
|
180
220
|
*/
|
|
181
|
-
deleteResults?:
|
|
221
|
+
readonly deleteResults?: ReadonlyMap<number, ClientDeleteResult>;
|
|
182
222
|
}
|
|
183
223
|
|
|
184
224
|
/** @public */
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Document } from 'bson';
|
|
2
|
+
|
|
1
3
|
import { ClientBulkWriteCursor } from '../../cursor/client_bulk_write_cursor';
|
|
2
4
|
import {
|
|
3
5
|
MongoClientBulkWriteError,
|
|
@@ -22,9 +24,9 @@ import { ClientBulkWriteResultsMerger } from './results_merger';
|
|
|
22
24
|
* @internal
|
|
23
25
|
*/
|
|
24
26
|
export class ClientBulkWriteExecutor {
|
|
25
|
-
client: MongoClient;
|
|
26
|
-
options: ClientBulkWriteOptions;
|
|
27
|
-
operations: AnyClientBulkWriteModel
|
|
27
|
+
private readonly client: MongoClient;
|
|
28
|
+
private readonly options: ClientBulkWriteOptions;
|
|
29
|
+
private readonly operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Instantiate the executor.
|
|
@@ -34,7 +36,7 @@ export class ClientBulkWriteExecutor {
|
|
|
34
36
|
*/
|
|
35
37
|
constructor(
|
|
36
38
|
client: MongoClient,
|
|
37
|
-
operations: AnyClientBulkWriteModel
|
|
39
|
+
operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>,
|
|
38
40
|
options?: ClientBulkWriteOptions
|
|
39
41
|
) {
|
|
40
42
|
if (operations.length === 0) {
|
|
@@ -75,7 +77,7 @@ export class ClientBulkWriteExecutor {
|
|
|
75
77
|
* for each, then merge the results into one.
|
|
76
78
|
* @returns The result.
|
|
77
79
|
*/
|
|
78
|
-
async execute(): Promise<ClientBulkWriteResult
|
|
80
|
+
async execute(): Promise<ClientBulkWriteResult> {
|
|
79
81
|
// The command builder will take the user provided models and potential split the batch
|
|
80
82
|
// into multiple commands due to size.
|
|
81
83
|
const pkFactory = this.client.s.options.pkFactory;
|
|
@@ -90,7 +92,7 @@ export class ClientBulkWriteExecutor {
|
|
|
90
92
|
const operation = new ClientBulkWriteOperation(commandBuilder, this.options);
|
|
91
93
|
await executeOperation(this.client, operation);
|
|
92
94
|
}
|
|
93
|
-
return
|
|
95
|
+
return ClientBulkWriteResultsMerger.unacknowledged();
|
|
94
96
|
} else {
|
|
95
97
|
const resultsMerger = new ClientBulkWriteResultsMerger(this.options);
|
|
96
98
|
// For each command will will create and exhaust a cursor for the results.
|
|
@@ -110,7 +112,7 @@ export class ClientBulkWriteExecutor {
|
|
|
110
112
|
message: 'Mongo client bulk write encountered an error during execution'
|
|
111
113
|
});
|
|
112
114
|
bulkWriteError.cause = error;
|
|
113
|
-
bulkWriteError.partialResult = resultsMerger.
|
|
115
|
+
bulkWriteError.partialResult = resultsMerger.bulkWriteResult;
|
|
114
116
|
throw bulkWriteError;
|
|
115
117
|
} else {
|
|
116
118
|
// Client side errors are just thrown.
|
|
@@ -126,11 +128,11 @@ export class ClientBulkWriteExecutor {
|
|
|
126
128
|
});
|
|
127
129
|
error.writeConcernErrors = resultsMerger.writeConcernErrors;
|
|
128
130
|
error.writeErrors = resultsMerger.writeErrors;
|
|
129
|
-
error.partialResult = resultsMerger.
|
|
131
|
+
error.partialResult = resultsMerger.bulkWriteResult;
|
|
130
132
|
throw error;
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
return resultsMerger.
|
|
135
|
+
return resultsMerger.bulkWriteResult;
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
}
|
|
@@ -11,17 +11,78 @@ import {
|
|
|
11
11
|
type ClientUpdateResult
|
|
12
12
|
} from './common';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Unacknowledged bulk writes are always the same.
|
|
16
|
+
*/
|
|
17
|
+
const UNACKNOWLEDGED = {
|
|
18
|
+
acknowledged: false,
|
|
19
|
+
insertedCount: 0,
|
|
20
|
+
upsertedCount: 0,
|
|
21
|
+
matchedCount: 0,
|
|
22
|
+
modifiedCount: 0,
|
|
23
|
+
deletedCount: 0,
|
|
24
|
+
insertResults: undefined,
|
|
25
|
+
updateResults: undefined,
|
|
26
|
+
deleteResults: undefined
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
interface ClientBulkWriteResultAccumulation {
|
|
30
|
+
/**
|
|
31
|
+
* Whether the bulk write was acknowledged.
|
|
32
|
+
*/
|
|
33
|
+
acknowledged: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The total number of documents inserted across all insert operations.
|
|
36
|
+
*/
|
|
37
|
+
insertedCount: number;
|
|
38
|
+
/**
|
|
39
|
+
* The total number of documents upserted across all update operations.
|
|
40
|
+
*/
|
|
41
|
+
upsertedCount: number;
|
|
42
|
+
/**
|
|
43
|
+
* The total number of documents matched across all update operations.
|
|
44
|
+
*/
|
|
45
|
+
matchedCount: number;
|
|
46
|
+
/**
|
|
47
|
+
* The total number of documents modified across all update operations.
|
|
48
|
+
*/
|
|
49
|
+
modifiedCount: number;
|
|
50
|
+
/**
|
|
51
|
+
* The total number of documents deleted across all delete operations.
|
|
52
|
+
*/
|
|
53
|
+
deletedCount: number;
|
|
54
|
+
/**
|
|
55
|
+
* The results of each individual insert operation that was successfully performed.
|
|
56
|
+
*/
|
|
57
|
+
insertResults?: Map<number, ClientInsertOneResult>;
|
|
58
|
+
/**
|
|
59
|
+
* The results of each individual update operation that was successfully performed.
|
|
60
|
+
*/
|
|
61
|
+
updateResults?: Map<number, ClientUpdateResult>;
|
|
62
|
+
/**
|
|
63
|
+
* The results of each individual delete operation that was successfully performed.
|
|
64
|
+
*/
|
|
65
|
+
deleteResults?: Map<number, ClientDeleteResult>;
|
|
66
|
+
}
|
|
67
|
+
|
|
14
68
|
/**
|
|
15
69
|
* Merges client bulk write cursor responses together into a single result.
|
|
16
70
|
* @internal
|
|
17
71
|
*/
|
|
18
72
|
export class ClientBulkWriteResultsMerger {
|
|
19
|
-
result:
|
|
20
|
-
options: ClientBulkWriteOptions;
|
|
21
|
-
currentBatchOffset: number;
|
|
73
|
+
private result: ClientBulkWriteResultAccumulation;
|
|
74
|
+
private options: ClientBulkWriteOptions;
|
|
75
|
+
private currentBatchOffset: number;
|
|
22
76
|
writeConcernErrors: Document[];
|
|
23
77
|
writeErrors: Map<number, ClientBulkWriteError>;
|
|
24
78
|
|
|
79
|
+
/**
|
|
80
|
+
* @returns The standard unacknowledged bulk write result.
|
|
81
|
+
*/
|
|
82
|
+
static unacknowledged(): ClientBulkWriteResult {
|
|
83
|
+
return UNACKNOWLEDGED;
|
|
84
|
+
}
|
|
85
|
+
|
|
25
86
|
/**
|
|
26
87
|
* Instantiate the merger.
|
|
27
88
|
* @param options - The options.
|
|
@@ -32,6 +93,7 @@ export class ClientBulkWriteResultsMerger {
|
|
|
32
93
|
this.writeConcernErrors = [];
|
|
33
94
|
this.writeErrors = new Map();
|
|
34
95
|
this.result = {
|
|
96
|
+
acknowledged: true,
|
|
35
97
|
insertedCount: 0,
|
|
36
98
|
upsertedCount: 0,
|
|
37
99
|
matchedCount: 0,
|
|
@@ -49,6 +111,23 @@ export class ClientBulkWriteResultsMerger {
|
|
|
49
111
|
}
|
|
50
112
|
}
|
|
51
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Get the bulk write result object.
|
|
116
|
+
*/
|
|
117
|
+
get bulkWriteResult(): ClientBulkWriteResult {
|
|
118
|
+
return {
|
|
119
|
+
acknowledged: this.result.acknowledged,
|
|
120
|
+
insertedCount: this.result.insertedCount,
|
|
121
|
+
upsertedCount: this.result.upsertedCount,
|
|
122
|
+
matchedCount: this.result.matchedCount,
|
|
123
|
+
modifiedCount: this.result.modifiedCount,
|
|
124
|
+
deletedCount: this.result.deletedCount,
|
|
125
|
+
insertResults: this.result.insertResults,
|
|
126
|
+
updateResults: this.result.updateResults,
|
|
127
|
+
deleteResults: this.result.deleteResults
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
52
131
|
/**
|
|
53
132
|
* Merge the results in the cursor to the existing result.
|
|
54
133
|
* @param currentBatchOffset - The offset index to the original models.
|