mongodb 6.8.1 → 6.9.0-dev.20240913.sha.8b0f3541
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 +14 -1
- package/lib/beta.d.ts +7905 -0
- package/lib/beta.js +21 -0
- package/lib/beta.js.map +1 -0
- package/lib/bson.js +5 -5
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +16 -21
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +10 -8
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +14 -3
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +25 -7
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/crypto_callbacks.js +6 -6
- package/lib/client-side-encryption/crypto_callbacks.js.map +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.js +9 -5
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -1
- package/lib/client-side-encryption/providers/aws.js +1 -2
- package/lib/client-side-encryption/providers/aws.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +5 -5
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/client-side-encryption/providers/gcp.js +1 -2
- package/lib/client-side-encryption/providers/gcp.js.map +1 -1
- package/lib/client-side-encryption/providers/index.js +2 -3
- package/lib/client-side-encryption/providers/index.js.map +1 -1
- package/lib/client-side-encryption/state_machine.js +9 -4
- package/lib/client-side-encryption/state_machine.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +4 -4
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +0 -2
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +2 -3
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js +0 -2
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +62 -5
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +10 -7
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +3 -5
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +11 -9
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +7 -3
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +5 -5
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/metrics.js +1 -1
- package/lib/cmap/metrics.js.map +1 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +5 -5
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +2 -2
- package/lib/cmap/wire_protocol/on_data.js +1 -2
- package/lib/cmap/wire_protocol/on_data.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
- package/lib/cmap/wire_protocol/responses.js +4 -4
- package/lib/cmap/wire_protocol/responses.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +2 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +12 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +22 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +3 -3
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +1 -1
- package/lib/db.js.map +1 -1
- package/lib/deps.js +16 -8
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +19 -14
- package/lib/error.js.map +1 -1
- package/lib/explain.js.map +1 -1
- package/lib/gridfs/download.js +1 -4
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +1 -1
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +0 -4
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +15 -1
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/mongo_logger.js +8 -8
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js +1 -0
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js +1 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/client_bulk_write/command_builder.js +198 -0
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
- package/lib/operations/client_bulk_write/common.js +3 -0
- package/lib/operations/client_bulk_write/common.js.map +1 -0
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +2 -2
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/execute_operation.js +111 -109
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -8
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/operation.js +5 -5
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/search_indexes/drop.js.map +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_concern.js.map +1 -1
- package/lib/read_preference.js +1 -1
- package/lib/read_preference.js.map +1 -1
- package/lib/resource_management.js +58 -0
- package/lib/resource_management.js.map +1 -0
- package/lib/sdam/common.js +3 -3
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/monitor.js +1 -5
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +2 -2
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +3 -3
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +5 -5
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -3
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +1 -1
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +221 -218
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +2 -3
- package/lib/sort.js.map +1 -1
- package/lib/timeout.js +0 -1
- package/lib/timeout.js.map +1 -1
- package/lib/transactions.js +2 -2
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +49 -51
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +2 -2
- package/lib/write_concern.js.map +1 -1
- package/mongodb.d.ts +150 -142
- package/package.json +27 -28
- package/src/beta.ts +22 -0
- package/src/bson.ts +1 -2
- package/src/bulk/common.ts +18 -18
- package/src/change_stream.ts +33 -15
- package/src/client-side-encryption/auto_encrypter.ts +18 -82
- package/src/client-side-encryption/client_encryption.ts +51 -54
- package/src/client-side-encryption/mongocryptd_manager.ts +10 -6
- package/src/client-side-encryption/state_machine.ts +28 -6
- package/src/cmap/auth/gssapi.ts +1 -1
- package/src/cmap/auth/mongodb_aws.ts +2 -2
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +2 -2
- package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +2 -2
- package/src/cmap/commands.ts +70 -5
- package/src/cmap/connect.ts +4 -1
- package/src/cmap/connection.ts +2 -2
- package/src/cmap/connection_pool.ts +17 -9
- package/src/cmap/connection_pool_events.ts +34 -2
- package/src/cmap/handshake/client_metadata.ts +1 -1
- package/src/cmap/wire_protocol/constants.ts +2 -2
- package/src/cmap/wire_protocol/shared.ts +1 -2
- package/src/collection.ts +16 -15
- package/src/connection_string.ts +10 -3
- package/src/constants.ts +1 -0
- package/src/cursor/abstract_cursor.ts +39 -14
- package/src/cursor/aggregation_cursor.ts +6 -4
- package/src/deps.ts +8 -1
- package/src/error.ts +33 -14
- package/src/gridfs/download.ts +28 -4
- package/src/gridfs/upload.ts +1 -6
- package/src/index.ts +5 -1
- package/src/mongo_client.ts +29 -5
- package/src/mongo_logger.ts +5 -3
- package/src/mongo_types.ts +69 -68
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/bulk_write.ts +2 -2
- package/src/operations/client_bulk_write/command_builder.ts +283 -0
- package/src/operations/client_bulk_write/common.ts +146 -0
- package/src/operations/command.ts +1 -1
- package/src/operations/execute_operation.ts +137 -131
- package/src/operations/find_and_modify.ts +2 -7
- package/src/operations/insert.ts +3 -4
- package/src/operations/operation.ts +7 -10
- package/src/operations/search_indexes/drop.ts +4 -1
- package/src/resource_management.ts +74 -0
- package/src/sdam/monitor.ts +3 -5
- package/src/sdam/server.ts +1 -1
- package/src/sdam/server_description.ts +5 -6
- package/src/sdam/srv_polling.ts +1 -2
- package/src/sessions.ts +291 -277
- package/src/sort.ts +1 -1
- package/src/timeout.ts +0 -1
- package/src/transactions.ts +1 -2
- package/src/utils.ts +9 -4
- package/src/write_concern.ts +2 -2
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { type Document } from '../../bson';
|
|
2
|
+
import { DocumentSequence } from '../../cmap/commands';
|
|
3
|
+
import type { Filter, OptionalId, UpdateFilter, WithoutId } from '../../mongo_types';
|
|
4
|
+
import { type CollationOptions } from '../command';
|
|
5
|
+
import { type Hint } from '../operation';
|
|
6
|
+
import type {
|
|
7
|
+
AnyClientBulkWriteModel,
|
|
8
|
+
ClientBulkWriteOptions,
|
|
9
|
+
ClientDeleteManyModel,
|
|
10
|
+
ClientDeleteOneModel,
|
|
11
|
+
ClientInsertOneModel,
|
|
12
|
+
ClientReplaceOneModel,
|
|
13
|
+
ClientUpdateManyModel,
|
|
14
|
+
ClientUpdateOneModel
|
|
15
|
+
} from './common';
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
export interface ClientBulkWriteCommand {
|
|
19
|
+
bulkWrite: 1;
|
|
20
|
+
errorsOnly: boolean;
|
|
21
|
+
ordered: boolean;
|
|
22
|
+
ops: DocumentSequence;
|
|
23
|
+
nsInfo: DocumentSequence;
|
|
24
|
+
bypassDocumentValidation?: boolean;
|
|
25
|
+
let?: Document;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @internal */
|
|
29
|
+
export class ClientBulkWriteCommandBuilder {
|
|
30
|
+
models: AnyClientBulkWriteModel[];
|
|
31
|
+
options: ClientBulkWriteOptions;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create the command builder.
|
|
35
|
+
* @param models - The client write models.
|
|
36
|
+
*/
|
|
37
|
+
constructor(models: AnyClientBulkWriteModel[], options: ClientBulkWriteOptions) {
|
|
38
|
+
this.models = models;
|
|
39
|
+
this.options = options;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets the errorsOnly value for the command, which is the inverse of the
|
|
44
|
+
* user provided verboseResults option. Defaults to true.
|
|
45
|
+
*/
|
|
46
|
+
get errorsOnly(): boolean {
|
|
47
|
+
if ('verboseResults' in this.options) {
|
|
48
|
+
return !this.options.verboseResults;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Build the bulk write commands from the models.
|
|
55
|
+
*/
|
|
56
|
+
buildCommands(): ClientBulkWriteCommand[] {
|
|
57
|
+
// Iterate the models to build the ops and nsInfo fields.
|
|
58
|
+
const operations = [];
|
|
59
|
+
let currentNamespaceIndex = 0;
|
|
60
|
+
const namespaces = new Map<string, number>();
|
|
61
|
+
for (const model of this.models) {
|
|
62
|
+
const ns = model.namespace;
|
|
63
|
+
const index = namespaces.get(ns);
|
|
64
|
+
if (index != null) {
|
|
65
|
+
operations.push(buildOperation(model, index));
|
|
66
|
+
} else {
|
|
67
|
+
namespaces.set(ns, currentNamespaceIndex);
|
|
68
|
+
operations.push(buildOperation(model, currentNamespaceIndex));
|
|
69
|
+
currentNamespaceIndex++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const nsInfo = Array.from(namespaces.keys(), ns => ({ ns }));
|
|
74
|
+
|
|
75
|
+
// The base command.
|
|
76
|
+
const command: ClientBulkWriteCommand = {
|
|
77
|
+
bulkWrite: 1,
|
|
78
|
+
errorsOnly: this.errorsOnly,
|
|
79
|
+
ordered: this.options.ordered ?? true,
|
|
80
|
+
ops: new DocumentSequence(operations),
|
|
81
|
+
nsInfo: new DocumentSequence(nsInfo)
|
|
82
|
+
};
|
|
83
|
+
// Add bypassDocumentValidation if it was present in the options.
|
|
84
|
+
if (this.options.bypassDocumentValidation != null) {
|
|
85
|
+
command.bypassDocumentValidation = this.options.bypassDocumentValidation;
|
|
86
|
+
}
|
|
87
|
+
// Add let if it was present in the options.
|
|
88
|
+
if (this.options.let) {
|
|
89
|
+
command.let = this.options.let;
|
|
90
|
+
}
|
|
91
|
+
return [command];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** @internal */
|
|
96
|
+
interface ClientInsertOperation {
|
|
97
|
+
insert: number;
|
|
98
|
+
document: OptionalId<Document>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Build the insert one operation.
|
|
103
|
+
* @param model - The insert one model.
|
|
104
|
+
* @param index - The namespace index.
|
|
105
|
+
* @returns the operation.
|
|
106
|
+
*/
|
|
107
|
+
export const buildInsertOneOperation = (
|
|
108
|
+
model: ClientInsertOneModel,
|
|
109
|
+
index: number
|
|
110
|
+
): ClientInsertOperation => {
|
|
111
|
+
const document: ClientInsertOperation = {
|
|
112
|
+
insert: index,
|
|
113
|
+
document: model.document
|
|
114
|
+
};
|
|
115
|
+
return document;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** @internal */
|
|
119
|
+
export interface ClientDeleteOperation {
|
|
120
|
+
delete: number;
|
|
121
|
+
multi: boolean;
|
|
122
|
+
filter: Filter<Document>;
|
|
123
|
+
hint?: Hint;
|
|
124
|
+
collation?: CollationOptions;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Build the delete one operation.
|
|
129
|
+
* @param model - The insert many model.
|
|
130
|
+
* @param index - The namespace index.
|
|
131
|
+
* @returns the operation.
|
|
132
|
+
*/
|
|
133
|
+
export const buildDeleteOneOperation = (model: ClientDeleteOneModel, index: number): Document => {
|
|
134
|
+
return createDeleteOperation(model, index, false);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Build the delete many operation.
|
|
139
|
+
* @param model - The delete many model.
|
|
140
|
+
* @param index - The namespace index.
|
|
141
|
+
* @returns the operation.
|
|
142
|
+
*/
|
|
143
|
+
export const buildDeleteManyOperation = (model: ClientDeleteManyModel, index: number): Document => {
|
|
144
|
+
return createDeleteOperation(model, index, true);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Creates a delete operation based on the parameters.
|
|
149
|
+
*/
|
|
150
|
+
function createDeleteOperation(
|
|
151
|
+
model: ClientDeleteOneModel | ClientDeleteManyModel,
|
|
152
|
+
index: number,
|
|
153
|
+
multi: boolean
|
|
154
|
+
): ClientDeleteOperation {
|
|
155
|
+
const document: ClientDeleteOperation = {
|
|
156
|
+
delete: index,
|
|
157
|
+
multi: multi,
|
|
158
|
+
filter: model.filter
|
|
159
|
+
};
|
|
160
|
+
if (model.hint) {
|
|
161
|
+
document.hint = model.hint;
|
|
162
|
+
}
|
|
163
|
+
if (model.collation) {
|
|
164
|
+
document.collation = model.collation;
|
|
165
|
+
}
|
|
166
|
+
return document;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @internal */
|
|
170
|
+
export interface ClientUpdateOperation {
|
|
171
|
+
update: number;
|
|
172
|
+
multi: boolean;
|
|
173
|
+
filter: Filter<Document>;
|
|
174
|
+
updateMods: UpdateFilter<Document> | Document[];
|
|
175
|
+
hint?: Hint;
|
|
176
|
+
upsert?: boolean;
|
|
177
|
+
arrayFilters?: Document[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Build the update one operation.
|
|
182
|
+
* @param model - The update one model.
|
|
183
|
+
* @param index - The namespace index.
|
|
184
|
+
* @returns the operation.
|
|
185
|
+
*/
|
|
186
|
+
export const buildUpdateOneOperation = (
|
|
187
|
+
model: ClientUpdateOneModel,
|
|
188
|
+
index: number
|
|
189
|
+
): ClientUpdateOperation => {
|
|
190
|
+
return createUpdateOperation(model, index, false);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Build the update many operation.
|
|
195
|
+
* @param model - The update many model.
|
|
196
|
+
* @param index - The namespace index.
|
|
197
|
+
* @returns the operation.
|
|
198
|
+
*/
|
|
199
|
+
export const buildUpdateManyOperation = (
|
|
200
|
+
model: ClientUpdateManyModel,
|
|
201
|
+
index: number
|
|
202
|
+
): ClientUpdateOperation => {
|
|
203
|
+
return createUpdateOperation(model, index, true);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Creates a delete operation based on the parameters.
|
|
208
|
+
*/
|
|
209
|
+
function createUpdateOperation(
|
|
210
|
+
model: ClientUpdateOneModel | ClientUpdateManyModel,
|
|
211
|
+
index: number,
|
|
212
|
+
multi: boolean
|
|
213
|
+
): ClientUpdateOperation {
|
|
214
|
+
const document: ClientUpdateOperation = {
|
|
215
|
+
update: index,
|
|
216
|
+
multi: multi,
|
|
217
|
+
filter: model.filter,
|
|
218
|
+
updateMods: model.update
|
|
219
|
+
};
|
|
220
|
+
if (model.hint) {
|
|
221
|
+
document.hint = model.hint;
|
|
222
|
+
}
|
|
223
|
+
if (model.upsert) {
|
|
224
|
+
document.upsert = model.upsert;
|
|
225
|
+
}
|
|
226
|
+
if (model.arrayFilters) {
|
|
227
|
+
document.arrayFilters = model.arrayFilters;
|
|
228
|
+
}
|
|
229
|
+
return document;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** @internal */
|
|
233
|
+
export interface ClientReplaceOneOperation {
|
|
234
|
+
update: number;
|
|
235
|
+
multi: boolean;
|
|
236
|
+
filter: Filter<Document>;
|
|
237
|
+
updateMods: WithoutId<Document>;
|
|
238
|
+
hint?: Hint;
|
|
239
|
+
upsert?: boolean;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Build the replace one operation.
|
|
244
|
+
* @param model - The replace one model.
|
|
245
|
+
* @param index - The namespace index.
|
|
246
|
+
* @returns the operation.
|
|
247
|
+
*/
|
|
248
|
+
export const buildReplaceOneOperation = (
|
|
249
|
+
model: ClientReplaceOneModel,
|
|
250
|
+
index: number
|
|
251
|
+
): ClientReplaceOneOperation => {
|
|
252
|
+
const document: ClientReplaceOneOperation = {
|
|
253
|
+
update: index,
|
|
254
|
+
multi: false,
|
|
255
|
+
filter: model.filter,
|
|
256
|
+
updateMods: model.replacement
|
|
257
|
+
};
|
|
258
|
+
if (model.hint) {
|
|
259
|
+
document.hint = model.hint;
|
|
260
|
+
}
|
|
261
|
+
if (model.upsert) {
|
|
262
|
+
document.upsert = model.upsert;
|
|
263
|
+
}
|
|
264
|
+
return document;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/** @internal */
|
|
268
|
+
export function buildOperation(model: AnyClientBulkWriteModel, index: number): Document {
|
|
269
|
+
switch (model.name) {
|
|
270
|
+
case 'insertOne':
|
|
271
|
+
return buildInsertOneOperation(model, index);
|
|
272
|
+
case 'deleteOne':
|
|
273
|
+
return buildDeleteOneOperation(model, index);
|
|
274
|
+
case 'deleteMany':
|
|
275
|
+
return buildDeleteManyOperation(model, index);
|
|
276
|
+
case 'updateOne':
|
|
277
|
+
return buildUpdateOneOperation(model, index);
|
|
278
|
+
case 'updateMany':
|
|
279
|
+
return buildUpdateManyOperation(model, index);
|
|
280
|
+
case 'replaceOne':
|
|
281
|
+
return buildReplaceOneOperation(model, index);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type Document } from '../../bson';
|
|
2
|
+
import type { Filter, OptionalId, UpdateFilter, WithoutId } from '../../mongo_types';
|
|
3
|
+
import type { CollationOptions, CommandOperationOptions } from '../../operations/command';
|
|
4
|
+
import type { Hint } from '../../operations/operation';
|
|
5
|
+
|
|
6
|
+
/** @public */
|
|
7
|
+
export interface ClientBulkWriteOptions extends CommandOperationOptions {
|
|
8
|
+
/**
|
|
9
|
+
* If true, when an insert fails, don't execute the remaining writes.
|
|
10
|
+
* If false, continue with remaining inserts when one fails.
|
|
11
|
+
* @defaultValue `true` - inserts are ordered by default
|
|
12
|
+
*/
|
|
13
|
+
ordered?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Allow driver to bypass schema validation.
|
|
16
|
+
* @defaultValue `false` - documents will be validated by default
|
|
17
|
+
**/
|
|
18
|
+
bypassDocumentValidation?: boolean;
|
|
19
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
20
|
+
let?: Document;
|
|
21
|
+
/**
|
|
22
|
+
* Whether detailed results for each successful operation should be included in the returned
|
|
23
|
+
* BulkWriteResult.
|
|
24
|
+
*/
|
|
25
|
+
verboseResults?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @public */
|
|
29
|
+
export interface ClientWriteModel {
|
|
30
|
+
/** The namespace for the write. */
|
|
31
|
+
namespace: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @public */
|
|
35
|
+
export interface ClientInsertOneModel extends ClientWriteModel {
|
|
36
|
+
name: 'insertOne';
|
|
37
|
+
/** The document to insert. */
|
|
38
|
+
document: OptionalId<Document>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @public */
|
|
42
|
+
export interface ClientDeleteOneModel extends ClientWriteModel {
|
|
43
|
+
name: 'deleteOne';
|
|
44
|
+
/**
|
|
45
|
+
* The filter used to determine if a document should be deleted.
|
|
46
|
+
* For a deleteOne operation, the first match is removed.
|
|
47
|
+
*/
|
|
48
|
+
filter: Filter<Document>;
|
|
49
|
+
/** Specifies a collation. */
|
|
50
|
+
collation?: CollationOptions;
|
|
51
|
+
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
52
|
+
hint?: Hint;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @public */
|
|
56
|
+
export interface ClientDeleteManyModel extends ClientWriteModel {
|
|
57
|
+
name: 'deleteMany';
|
|
58
|
+
/**
|
|
59
|
+
* The filter used to determine if a document should be deleted.
|
|
60
|
+
* For a deleteMany operation, all matches are removed.
|
|
61
|
+
*/
|
|
62
|
+
filter: Filter<Document>;
|
|
63
|
+
/** Specifies a collation. */
|
|
64
|
+
collation?: CollationOptions;
|
|
65
|
+
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
66
|
+
hint?: Hint;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @public */
|
|
70
|
+
export interface ClientReplaceOneModel extends ClientWriteModel {
|
|
71
|
+
name: 'replaceOne';
|
|
72
|
+
/**
|
|
73
|
+
* The filter used to determine if a document should be replaced.
|
|
74
|
+
* For a replaceOne operation, the first match is replaced.
|
|
75
|
+
*/
|
|
76
|
+
filter: Filter<Document>;
|
|
77
|
+
/** The document with which to replace the matched document. */
|
|
78
|
+
replacement: WithoutId<Document>;
|
|
79
|
+
/** Specifies a collation. */
|
|
80
|
+
collation?: CollationOptions;
|
|
81
|
+
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
82
|
+
hint?: Hint;
|
|
83
|
+
/** When true, creates a new document if no document matches the query. */
|
|
84
|
+
upsert?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @public */
|
|
88
|
+
export interface ClientUpdateOneModel extends ClientWriteModel {
|
|
89
|
+
name: 'updateOne';
|
|
90
|
+
/**
|
|
91
|
+
* The filter used to determine if a document should be updated.
|
|
92
|
+
* For an updateOne operation, the first match is updated.
|
|
93
|
+
*/
|
|
94
|
+
filter: Filter<Document>;
|
|
95
|
+
/**
|
|
96
|
+
* The modifications to apply. The value can be either:
|
|
97
|
+
* UpdateFilter<Document> - A document that contains update operator expressions,
|
|
98
|
+
* Document[] - an aggregation pipeline.
|
|
99
|
+
*/
|
|
100
|
+
update: UpdateFilter<Document> | Document[];
|
|
101
|
+
/** A set of filters specifying to which array elements an update should apply. */
|
|
102
|
+
arrayFilters?: Document[];
|
|
103
|
+
/** Specifies a collation. */
|
|
104
|
+
collation?: CollationOptions;
|
|
105
|
+
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
106
|
+
hint?: Hint;
|
|
107
|
+
/** When true, creates a new document if no document matches the query. */
|
|
108
|
+
upsert?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @public */
|
|
112
|
+
export interface ClientUpdateManyModel extends ClientWriteModel {
|
|
113
|
+
name: 'updateMany';
|
|
114
|
+
/**
|
|
115
|
+
* The filter used to determine if a document should be updated.
|
|
116
|
+
* For an updateMany operation, all matches are updated.
|
|
117
|
+
*/
|
|
118
|
+
filter: Filter<Document>;
|
|
119
|
+
/**
|
|
120
|
+
* The modifications to apply. The value can be either:
|
|
121
|
+
* UpdateFilter<Document> - A document that contains update operator expressions,
|
|
122
|
+
* Document[] - an aggregation pipeline.
|
|
123
|
+
*/
|
|
124
|
+
update: UpdateFilter<Document> | Document[];
|
|
125
|
+
/** A set of filters specifying to which array elements an update should apply. */
|
|
126
|
+
arrayFilters?: Document[];
|
|
127
|
+
/** Specifies a collation. */
|
|
128
|
+
collation?: CollationOptions;
|
|
129
|
+
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
130
|
+
hint?: Hint;
|
|
131
|
+
/** When true, creates a new document if no document matches the query. */
|
|
132
|
+
upsert?: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Used to represent any of the client bulk write models that can be passed as an array
|
|
137
|
+
* to MongoClient#bulkWrite.
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
export type AnyClientBulkWriteModel =
|
|
141
|
+
| ClientInsertOneModel
|
|
142
|
+
| ClientReplaceOneModel
|
|
143
|
+
| ClientUpdateOneModel
|
|
144
|
+
| ClientUpdateManyModel
|
|
145
|
+
| ClientDeleteOneModel
|
|
146
|
+
| ClientDeleteManyModel;
|
|
@@ -104,7 +104,7 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
|
|
|
104
104
|
if (this.hasAspect(Aspect.EXPLAINABLE)) {
|
|
105
105
|
return this.explain == null;
|
|
106
106
|
}
|
|
107
|
-
return
|
|
107
|
+
return super.canRetryWrite;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
public async executeCommand<T extends MongoDBResponseConstructor>(
|