@depup/mongodb 7.1.0-depup.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/LICENSE.md +201 -0
- package/README.md +33 -0
- package/etc/prepare.js +12 -0
- package/lib/admin.js +136 -0
- package/lib/admin.js.map +1 -0
- package/lib/bson.js +85 -0
- package/lib/bson.js.map +1 -0
- package/lib/bulk/common.js +835 -0
- package/lib/bulk/common.js.map +1 -0
- package/lib/bulk/ordered.js +67 -0
- package/lib/bulk/ordered.js.map +1 -0
- package/lib/bulk/unordered.js +92 -0
- package/lib/bulk/unordered.js.map +1 -0
- package/lib/change_stream.js +513 -0
- package/lib/change_stream.js.map +1 -0
- package/lib/client-side-encryption/auto_encrypter.js +272 -0
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
- package/lib/client-side-encryption/client_encryption.js +609 -0
- package/lib/client-side-encryption/client_encryption.js.map +1 -0
- package/lib/client-side-encryption/errors.js +138 -0
- package/lib/client-side-encryption/errors.js.map +1 -0
- package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
- package/lib/client-side-encryption/providers/aws.js +23 -0
- package/lib/client-side-encryption/providers/aws.js.map +1 -0
- package/lib/client-side-encryption/providers/azure.js +132 -0
- package/lib/client-side-encryption/providers/azure.js.map +1 -0
- package/lib/client-side-encryption/providers/gcp.js +16 -0
- package/lib/client-side-encryption/providers/gcp.js.map +1 -0
- package/lib/client-side-encryption/providers/index.js +43 -0
- package/lib/client-side-encryption/providers/index.js.map +1 -0
- package/lib/client-side-encryption/state_machine.js +427 -0
- package/lib/client-side-encryption/state_machine.js.map +1 -0
- package/lib/cmap/auth/auth_provider.js +51 -0
- package/lib/cmap/auth/auth_provider.js.map +1 -0
- package/lib/cmap/auth/aws4.js +161 -0
- package/lib/cmap/auth/aws4.js.map +1 -0
- package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +155 -0
- package/lib/cmap/auth/gssapi.js.map +1 -0
- package/lib/cmap/auth/mongo_credentials.js +169 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -0
- package/lib/cmap/auth/mongodb_aws.js +128 -0
- package/lib/cmap/auth/mongodb_aws.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +32 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +23 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +73 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +26 -0
- package/lib/cmap/auth/plain.js.map +1 -0
- package/lib/cmap/auth/providers.js +22 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +254 -0
- package/lib/cmap/auth/scram.js.map +1 -0
- package/lib/cmap/auth/x509.js +36 -0
- package/lib/cmap/auth/x509.js.map +1 -0
- package/lib/cmap/command_monitoring_events.js +223 -0
- package/lib/cmap/command_monitoring_events.js.map +1 -0
- package/lib/cmap/commands.js +535 -0
- package/lib/cmap/commands.js.map +1 -0
- package/lib/cmap/connect.js +381 -0
- package/lib/cmap/connect.js.map +1 -0
- package/lib/cmap/connection.js +571 -0
- package/lib/cmap/connection.js.map +1 -0
- package/lib/cmap/connection_pool.js +558 -0
- package/lib/cmap/connection_pool.js.map +1 -0
- package/lib/cmap/connection_pool_events.js +190 -0
- package/lib/cmap/connection_pool_events.js.map +1 -0
- package/lib/cmap/errors.js +108 -0
- package/lib/cmap/errors.js.map +1 -0
- package/lib/cmap/handshake/client_metadata.js +242 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +70 -0
- package/lib/cmap/stream_description.js.map +1 -0
- package/lib/cmap/wire_protocol/compression.js +178 -0
- package/lib/cmap/wire_protocol/compression.js.map +1 -0
- package/lib/cmap/wire_protocol/constants.js +21 -0
- package/lib/cmap/wire_protocol/constants.js.map +1 -0
- package/lib/cmap/wire_protocol/on_data.js +111 -0
- package/lib/cmap/wire_protocol/on_data.js.map +1 -0
- package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +315 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/cmap/wire_protocol/shared.js +35 -0
- package/lib/cmap/wire_protocol/shared.js.map +1 -0
- package/lib/collection.js +751 -0
- package/lib/collection.js.map +1 -0
- package/lib/connection_string.js +1090 -0
- package/lib/connection_string.js.map +1 -0
- package/lib/constants.js +170 -0
- package/lib/constants.js.map +1 -0
- package/lib/cursor/abstract_cursor.js +924 -0
- package/lib/cursor/abstract_cursor.js.map +1 -0
- package/lib/cursor/aggregation_cursor.js +164 -0
- package/lib/cursor/aggregation_cursor.js.map +1 -0
- package/lib/cursor/change_stream_cursor.js +104 -0
- package/lib/cursor/change_stream_cursor.js.map +1 -0
- package/lib/cursor/client_bulk_write_cursor.js +52 -0
- package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
- package/lib/cursor/explainable_cursor.js +36 -0
- package/lib/cursor/explainable_cursor.js.map +1 -0
- package/lib/cursor/find_cursor.js +399 -0
- package/lib/cursor/find_cursor.js.map +1 -0
- package/lib/cursor/list_collections_cursor.js +34 -0
- package/lib/cursor/list_collections_cursor.js.map +1 -0
- package/lib/cursor/list_indexes_cursor.js +32 -0
- package/lib/cursor/list_indexes_cursor.js.map +1 -0
- package/lib/cursor/list_search_indexes_cursor.js +14 -0
- package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
- package/lib/cursor/run_command_cursor.js +94 -0
- package/lib/cursor/run_command_cursor.js.map +1 -0
- package/lib/db.js +419 -0
- package/lib/db.js.map +1 -0
- package/lib/deps.js +112 -0
- package/lib/deps.js.map +1 -0
- package/lib/encrypter.js +106 -0
- package/lib/encrypter.js.map +1 -0
- package/lib/error.js +1380 -0
- package/lib/error.js.map +1 -0
- package/lib/explain.js +59 -0
- package/lib/explain.js.map +1 -0
- package/lib/gridfs/download.js +305 -0
- package/lib/gridfs/download.js.map +1 -0
- package/lib/gridfs/index.js +164 -0
- package/lib/gridfs/index.js.map +1 -0
- package/lib/gridfs/upload.js +358 -0
- package/lib/gridfs/upload.js.map +1 -0
- package/lib/index.js +193 -0
- package/lib/index.js.map +1 -0
- package/lib/mongo_client.js +557 -0
- package/lib/mongo_client.js.map +1 -0
- package/lib/mongo_client_auth_providers.js +80 -0
- package/lib/mongo_client_auth_providers.js.map +1 -0
- package/lib/mongo_logger.js +655 -0
- package/lib/mongo_logger.js.map +1 -0
- package/lib/mongo_types.js +56 -0
- package/lib/mongo_types.js.map +1 -0
- package/lib/operations/aggregate.js +90 -0
- package/lib/operations/aggregate.js.map +1 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
- package/lib/operations/client_bulk_write/command_builder.js +340 -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/client_bulk_write/executor.js +120 -0
- package/lib/operations/client_bulk_write/executor.js.map +1 -0
- package/lib/operations/client_bulk_write/results_merger.js +204 -0
- package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
- package/lib/operations/command.js +83 -0
- package/lib/operations/command.js.map +1 -0
- package/lib/operations/count.js +45 -0
- package/lib/operations/count.js.map +1 -0
- package/lib/operations/create_collection.js +109 -0
- package/lib/operations/create_collection.js.map +1 -0
- package/lib/operations/delete.js +125 -0
- package/lib/operations/delete.js.map +1 -0
- package/lib/operations/distinct.js +61 -0
- package/lib/operations/distinct.js.map +1 -0
- package/lib/operations/drop.js +93 -0
- package/lib/operations/drop.js.map +1 -0
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/estimated_document_count.js +41 -0
- package/lib/operations/estimated_document_count.js.map +1 -0
- package/lib/operations/execute_operation.js +239 -0
- package/lib/operations/execute_operation.js.map +1 -0
- package/lib/operations/find.js +148 -0
- package/lib/operations/find.js.map +1 -0
- package/lib/operations/find_and_modify.js +158 -0
- package/lib/operations/find_and_modify.js.map +1 -0
- package/lib/operations/get_more.js +62 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +186 -0
- package/lib/operations/indexes.js.map +1 -0
- package/lib/operations/insert.js +70 -0
- package/lib/operations/insert.js.map +1 -0
- package/lib/operations/kill_cursors.js +43 -0
- package/lib/operations/kill_cursors.js.map +1 -0
- package/lib/operations/list_collections.js +53 -0
- package/lib/operations/list_collections.js.map +1 -0
- package/lib/operations/list_databases.js +40 -0
- package/lib/operations/list_databases.js.map +1 -0
- package/lib/operations/operation.js +102 -0
- package/lib/operations/operation.js.map +1 -0
- package/lib/operations/profiling_level.js +43 -0
- package/lib/operations/profiling_level.js.map +1 -0
- package/lib/operations/remove_user.js +27 -0
- package/lib/operations/remove_user.js.map +1 -0
- package/lib/operations/rename.js +38 -0
- package/lib/operations/rename.js.map +1 -0
- package/lib/operations/run_command.js +47 -0
- package/lib/operations/run_command.js.map +1 -0
- package/lib/operations/search_indexes/create.js +33 -0
- package/lib/operations/search_indexes/create.js.map +1 -0
- package/lib/operations/search_indexes/drop.js +43 -0
- package/lib/operations/search_indexes/drop.js.map +1 -0
- package/lib/operations/search_indexes/update.js +35 -0
- package/lib/operations/search_indexes/update.js.map +1 -0
- package/lib/operations/set_profiling_level.js +53 -0
- package/lib/operations/set_profiling_level.js.map +1 -0
- package/lib/operations/stats.js +27 -0
- package/lib/operations/stats.js.map +1 -0
- package/lib/operations/update.js +188 -0
- package/lib/operations/update.js.map +1 -0
- package/lib/operations/validate_collection.js +37 -0
- package/lib/operations/validate_collection.js.map +1 -0
- package/lib/read_concern.js +73 -0
- package/lib/read_concern.js.map +1 -0
- package/lib/read_preference.js +191 -0
- package/lib/read_preference.js.map +1 -0
- package/lib/sdam/common.js +49 -0
- package/lib/sdam/common.js.map +1 -0
- package/lib/sdam/events.js +146 -0
- package/lib/sdam/events.js.map +1 -0
- package/lib/sdam/monitor.js +544 -0
- package/lib/sdam/monitor.js.map +1 -0
- package/lib/sdam/server.js +404 -0
- package/lib/sdam/server.js.map +1 -0
- package/lib/sdam/server_description.js +204 -0
- package/lib/sdam/server_description.js.map +1 -0
- package/lib/sdam/server_selection.js +294 -0
- package/lib/sdam/server_selection.js.map +1 -0
- package/lib/sdam/server_selection_events.js +85 -0
- package/lib/sdam/server_selection_events.js.map +1 -0
- package/lib/sdam/srv_polling.js +108 -0
- package/lib/sdam/srv_polling.js.map +1 -0
- package/lib/sdam/topology.js +652 -0
- package/lib/sdam/topology.js.map +1 -0
- package/lib/sdam/topology_description.js +383 -0
- package/lib/sdam/topology_description.js.map +1 -0
- package/lib/sessions.js +892 -0
- package/lib/sessions.js.map +1 -0
- package/lib/sort.js +103 -0
- package/lib/sort.js.map +1 -0
- package/lib/timeout.js +296 -0
- package/lib/timeout.js.map +1 -0
- package/lib/transactions.js +135 -0
- package/lib/transactions.js.map +1 -0
- package/lib/utils.js +1163 -0
- package/lib/utils.js.map +1 -0
- package/lib/write_concern.js +100 -0
- package/lib/write_concern.js.map +1 -0
- package/mongodb.d.ts +9018 -0
- package/package.json +197 -0
- package/src/admin.ts +173 -0
- package/src/bson.ts +149 -0
- package/src/bulk/common.ts +1251 -0
- package/src/bulk/ordered.ts +83 -0
- package/src/bulk/unordered.ts +115 -0
- package/src/change_stream.ts +1160 -0
- package/src/client-side-encryption/auto_encrypter.ts +469 -0
- package/src/client-side-encryption/client_encryption.ts +1150 -0
- package/src/client-side-encryption/errors.ts +144 -0
- package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
- package/src/client-side-encryption/providers/aws.ts +33 -0
- package/src/client-side-encryption/providers/azure.ts +181 -0
- package/src/client-side-encryption/providers/gcp.ts +16 -0
- package/src/client-side-encryption/providers/index.ts +207 -0
- package/src/client-side-encryption/state_machine.ts +651 -0
- package/src/cmap/auth/auth_provider.ts +77 -0
- package/src/cmap/auth/aws4.ts +207 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
- package/src/cmap/auth/gssapi.ts +203 -0
- package/src/cmap/auth/mongo_credentials.ts +292 -0
- package/src/cmap/auth/mongodb_aws.ts +179 -0
- package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
- package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
- package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
- package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
- package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
- package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
- package/src/cmap/auth/mongodb_oidc.ts +185 -0
- package/src/cmap/auth/plain.ts +25 -0
- package/src/cmap/auth/providers.ts +22 -0
- package/src/cmap/auth/scram.ts +344 -0
- package/src/cmap/auth/x509.ts +43 -0
- package/src/cmap/command_monitoring_events.ts +316 -0
- package/src/cmap/commands.ts +788 -0
- package/src/cmap/connect.ts +518 -0
- package/src/cmap/connection.ts +931 -0
- package/src/cmap/connection_pool.ts +831 -0
- package/src/cmap/connection_pool_events.ts +300 -0
- package/src/cmap/errors.ts +119 -0
- package/src/cmap/handshake/client_metadata.ts +353 -0
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +96 -0
- package/src/cmap/wire_protocol/compression.ts +211 -0
- package/src/cmap/wire_protocol/constants.ts +17 -0
- package/src/cmap/wire_protocol/on_data.ts +139 -0
- package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
- package/src/cmap/wire_protocol/responses.ts +393 -0
- package/src/cmap/wire_protocol/shared.ts +48 -0
- package/src/collection.ts +1314 -0
- package/src/connection_string.ts +1297 -0
- package/src/constants.ts +176 -0
- package/src/cursor/abstract_cursor.ts +1247 -0
- package/src/cursor/aggregation_cursor.ts +245 -0
- package/src/cursor/change_stream_cursor.ts +171 -0
- package/src/cursor/client_bulk_write_cursor.ts +83 -0
- package/src/cursor/explainable_cursor.ts +51 -0
- package/src/cursor/find_cursor.ts +497 -0
- package/src/cursor/list_collections_cursor.ts +50 -0
- package/src/cursor/list_indexes_cursor.ts +37 -0
- package/src/cursor/list_search_indexes_cursor.ts +20 -0
- package/src/cursor/run_command_cursor.ts +178 -0
- package/src/db.ts +621 -0
- package/src/deps.ts +227 -0
- package/src/encrypter.ts +127 -0
- package/src/error.ts +1567 -0
- package/src/explain.ts +124 -0
- package/src/gridfs/download.ts +483 -0
- package/src/gridfs/index.ts +264 -0
- package/src/gridfs/upload.ts +537 -0
- package/src/index.ts +633 -0
- package/src/mongo_client.ts +1155 -0
- package/src/mongo_client_auth_providers.ts +87 -0
- package/src/mongo_logger.ts +1081 -0
- package/src/mongo_types.ts +678 -0
- package/src/operations/aggregate.ts +153 -0
- package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
- package/src/operations/client_bulk_write/command_builder.ts +487 -0
- package/src/operations/client_bulk_write/common.ts +276 -0
- package/src/operations/client_bulk_write/executor.ts +149 -0
- package/src/operations/client_bulk_write/results_merger.ts +260 -0
- package/src/operations/command.ts +171 -0
- package/src/operations/count.ts +74 -0
- package/src/operations/create_collection.ts +218 -0
- package/src/operations/delete.ts +183 -0
- package/src/operations/distinct.ts +92 -0
- package/src/operations/drop.ts +130 -0
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/estimated_document_count.ts +61 -0
- package/src/operations/execute_operation.ts +319 -0
- package/src/operations/find.ts +254 -0
- package/src/operations/find_and_modify.ts +319 -0
- package/src/operations/get_more.ts +108 -0
- package/src/operations/indexes.ts +418 -0
- package/src/operations/insert.ts +108 -0
- package/src/operations/kill_cursors.ts +64 -0
- package/src/operations/list_collections.ts +108 -0
- package/src/operations/list_databases.ts +68 -0
- package/src/operations/operation.ts +181 -0
- package/src/operations/profiling_level.ts +46 -0
- package/src/operations/remove_user.ts +36 -0
- package/src/operations/rename.ts +60 -0
- package/src/operations/run_command.ts +79 -0
- package/src/operations/search_indexes/create.ts +56 -0
- package/src/operations/search_indexes/drop.ts +58 -0
- package/src/operations/search_indexes/update.ts +45 -0
- package/src/operations/set_profiling_level.ts +74 -0
- package/src/operations/stats.ts +37 -0
- package/src/operations/update.ts +318 -0
- package/src/operations/validate_collection.ts +50 -0
- package/src/read_concern.ts +88 -0
- package/src/read_preference.ts +256 -0
- package/src/sdam/common.ts +74 -0
- package/src/sdam/events.ts +219 -0
- package/src/sdam/monitor.ts +771 -0
- package/src/sdam/server.ts +595 -0
- package/src/sdam/server_description.ts +297 -0
- package/src/sdam/server_selection.ts +415 -0
- package/src/sdam/server_selection_events.ts +142 -0
- package/src/sdam/srv_polling.ts +146 -0
- package/src/sdam/topology.ts +1100 -0
- package/src/sdam/topology_description.ts +548 -0
- package/src/sessions.ts +1244 -0
- package/src/sort.ts +141 -0
- package/src/timeout.ts +405 -0
- package/src/transactions.ts +181 -0
- package/src/utils.ts +1434 -0
- package/src/write_concern.ts +183 -0
- package/tsconfig.json +46 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientBulkWriteExecutor = void 0;
|
|
4
|
+
const abstract_cursor_1 = require("../../cursor/abstract_cursor");
|
|
5
|
+
const client_bulk_write_cursor_1 = require("../../cursor/client_bulk_write_cursor");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const timeout_1 = require("../../timeout");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const write_concern_1 = require("../../write_concern");
|
|
10
|
+
const execute_operation_1 = require("../execute_operation");
|
|
11
|
+
const client_bulk_write_1 = require("./client_bulk_write");
|
|
12
|
+
const command_builder_1 = require("./command_builder");
|
|
13
|
+
const results_merger_1 = require("./results_merger");
|
|
14
|
+
/**
|
|
15
|
+
* Responsible for executing a client bulk write.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
class ClientBulkWriteExecutor {
|
|
19
|
+
/**
|
|
20
|
+
* Instantiate the executor.
|
|
21
|
+
* @param client - The mongo client.
|
|
22
|
+
* @param operations - The user supplied bulk write models.
|
|
23
|
+
* @param options - The bulk write options.
|
|
24
|
+
*/
|
|
25
|
+
constructor(client, operations, options) {
|
|
26
|
+
if (operations.length === 0) {
|
|
27
|
+
throw new error_1.MongoClientBulkWriteExecutionError('No client bulk write models were provided.');
|
|
28
|
+
}
|
|
29
|
+
this.client = client;
|
|
30
|
+
this.operations = operations;
|
|
31
|
+
this.options = {
|
|
32
|
+
ordered: true,
|
|
33
|
+
bypassDocumentValidation: false,
|
|
34
|
+
verboseResults: false,
|
|
35
|
+
...options
|
|
36
|
+
};
|
|
37
|
+
// If no write concern was provided, we inherit one from the client.
|
|
38
|
+
if (!this.options.writeConcern) {
|
|
39
|
+
this.options.writeConcern = write_concern_1.WriteConcern.fromOptions(this.client.s.options);
|
|
40
|
+
}
|
|
41
|
+
if (this.options.writeConcern?.w === 0) {
|
|
42
|
+
if (this.options.verboseResults) {
|
|
43
|
+
throw new error_1.MongoInvalidArgumentError('Cannot request unacknowledged write concern and verbose results');
|
|
44
|
+
}
|
|
45
|
+
if (this.options.ordered) {
|
|
46
|
+
throw new error_1.MongoInvalidArgumentError('Cannot request unacknowledged write concern and ordered writes');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Execute the client bulk write. Will split commands into batches and exhaust the cursors
|
|
52
|
+
* for each, then merge the results into one.
|
|
53
|
+
* @returns The result.
|
|
54
|
+
*/
|
|
55
|
+
async execute() {
|
|
56
|
+
// The command builder will take the user provided models and potential split the batch
|
|
57
|
+
// into multiple commands due to size.
|
|
58
|
+
const pkFactory = this.client.s.options.pkFactory;
|
|
59
|
+
const commandBuilder = new command_builder_1.ClientBulkWriteCommandBuilder(this.operations, this.options, pkFactory);
|
|
60
|
+
// Unacknowledged writes need to execute all batches and return { ok: 1}
|
|
61
|
+
const resolvedOptions = (0, utils_1.resolveTimeoutOptions)(this.client, this.options);
|
|
62
|
+
const context = timeout_1.TimeoutContext.create(resolvedOptions);
|
|
63
|
+
if (this.options.writeConcern?.w === 0) {
|
|
64
|
+
while (commandBuilder.hasNextBatch()) {
|
|
65
|
+
const operation = new client_bulk_write_1.ClientBulkWriteOperation(commandBuilder, this.options);
|
|
66
|
+
await (0, execute_operation_1.executeOperation)(this.client, operation, context);
|
|
67
|
+
}
|
|
68
|
+
return results_merger_1.ClientBulkWriteResultsMerger.unacknowledged();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const resultsMerger = new results_merger_1.ClientBulkWriteResultsMerger(this.options);
|
|
72
|
+
// For each command will will create and exhaust a cursor for the results.
|
|
73
|
+
while (commandBuilder.hasNextBatch()) {
|
|
74
|
+
const cursorContext = new abstract_cursor_1.CursorTimeoutContext(context, Symbol());
|
|
75
|
+
const options = {
|
|
76
|
+
...this.options,
|
|
77
|
+
timeoutContext: cursorContext,
|
|
78
|
+
...(resolvedOptions.timeoutMS != null && { timeoutMode: abstract_cursor_1.CursorTimeoutMode.LIFETIME })
|
|
79
|
+
};
|
|
80
|
+
const cursor = new client_bulk_write_cursor_1.ClientBulkWriteCursor(this.client, commandBuilder, options);
|
|
81
|
+
try {
|
|
82
|
+
await resultsMerger.merge(cursor);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Write concern errors are recorded in the writeConcernErrors field on MongoClientBulkWriteError.
|
|
86
|
+
// When a write concern error is encountered, it should not terminate execution of the bulk write
|
|
87
|
+
// for either ordered or unordered bulk writes. However, drivers MUST throw an exception at the end
|
|
88
|
+
// of execution if any write concern errors were observed.
|
|
89
|
+
if (error instanceof error_1.MongoServerError && !(error instanceof error_1.MongoClientBulkWriteError)) {
|
|
90
|
+
// Server side errors need to be wrapped inside a MongoClientBulkWriteError, where the root
|
|
91
|
+
// cause is the error property and a partial result is to be included.
|
|
92
|
+
const bulkWriteError = new error_1.MongoClientBulkWriteError({
|
|
93
|
+
message: 'Mongo client bulk write encountered an error during execution'
|
|
94
|
+
});
|
|
95
|
+
bulkWriteError.cause = error;
|
|
96
|
+
bulkWriteError.partialResult = resultsMerger.bulkWriteResult;
|
|
97
|
+
throw bulkWriteError;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Client side errors are just thrown.
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// If we have write concern errors or unordered write errors at the end we throw.
|
|
106
|
+
if (resultsMerger.writeConcernErrors.length > 0 || resultsMerger.writeErrors.size > 0) {
|
|
107
|
+
const error = new error_1.MongoClientBulkWriteError({
|
|
108
|
+
message: 'Mongo client bulk write encountered errors during execution.'
|
|
109
|
+
});
|
|
110
|
+
error.writeConcernErrors = resultsMerger.writeConcernErrors;
|
|
111
|
+
error.writeErrors = resultsMerger.writeErrors;
|
|
112
|
+
error.partialResult = resultsMerger.bulkWriteResult;
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
return resultsMerger.bulkWriteResult;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ClientBulkWriteExecutor = ClientBulkWriteExecutor;
|
|
120
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/operations/client_bulk_write/executor.ts"],"names":[],"mappings":";;;AACA,kEAAuF;AACvF,oFAA8E;AAC9E,uCAKqB;AAErB,2CAA+C;AAC/C,uCAAoD;AACpD,uDAAmD;AACnD,4DAAwD;AACxD,2DAA+D;AAC/D,uDAAkE;AAMlE,qDAAgE;AAEhE;;;GAGG;AACH,MAAa,uBAAuB;IAKlC;;;;;OAKG;IACH,YACE,MAAmB,EACnB,UAA4D,EAC5D,OAAgC;QAEhC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,0CAAkC,CAAC,4CAA4C,CAAC,CAAC;QAC7F,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE,IAAI;YACb,wBAAwB,EAAE,KAAK;YAC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ACvB,CAAC;yBAAM,CAAC;wBACN,sCAAsC;wBACtC,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC;YAED,iFAAiF;YACjF,IAAI,aAAa,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;gBACtF,MAAM,KAAK,GAAG,IAAI,iCAAyB,CAAC;oBAC1C,OAAO,EAAE,8DAA8D;iBACxE,CAAC,CAAC;gBACH,KAAK,CAAC,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,CAAC;gBAC5D,KAAK,CAAC,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC;gBAC9C,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,eAAe,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,aAAa,CAAC,eAAe,CAAC;QACvC,CAAC;IACH,CAAC;CACF;AAzHD,0DAyHC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientBulkWriteResultsMerger = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
const error_1 = require("../../error");
|
|
6
|
+
/**
|
|
7
|
+
* Unacknowledged bulk writes are always the same.
|
|
8
|
+
*/
|
|
9
|
+
const UNACKNOWLEDGED = {
|
|
10
|
+
acknowledged: false,
|
|
11
|
+
insertedCount: 0,
|
|
12
|
+
upsertedCount: 0,
|
|
13
|
+
matchedCount: 0,
|
|
14
|
+
modifiedCount: 0,
|
|
15
|
+
deletedCount: 0,
|
|
16
|
+
insertResults: undefined,
|
|
17
|
+
updateResults: undefined,
|
|
18
|
+
deleteResults: undefined
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Merges client bulk write cursor responses together into a single result.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
class ClientBulkWriteResultsMerger {
|
|
25
|
+
/**
|
|
26
|
+
* @returns The standard unacknowledged bulk write result.
|
|
27
|
+
*/
|
|
28
|
+
static unacknowledged() {
|
|
29
|
+
return UNACKNOWLEDGED;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Instantiate the merger.
|
|
33
|
+
* @param options - The options.
|
|
34
|
+
*/
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.options = options;
|
|
37
|
+
this.currentBatchOffset = 0;
|
|
38
|
+
this.writeConcernErrors = [];
|
|
39
|
+
this.writeErrors = new Map();
|
|
40
|
+
this.result = {
|
|
41
|
+
acknowledged: true,
|
|
42
|
+
insertedCount: 0,
|
|
43
|
+
upsertedCount: 0,
|
|
44
|
+
matchedCount: 0,
|
|
45
|
+
modifiedCount: 0,
|
|
46
|
+
deletedCount: 0,
|
|
47
|
+
insertResults: undefined,
|
|
48
|
+
updateResults: undefined,
|
|
49
|
+
deleteResults: undefined
|
|
50
|
+
};
|
|
51
|
+
if (options.verboseResults) {
|
|
52
|
+
this.result.insertResults = new Map();
|
|
53
|
+
this.result.updateResults = new Map();
|
|
54
|
+
this.result.deleteResults = new Map();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the bulk write result object.
|
|
59
|
+
*/
|
|
60
|
+
get bulkWriteResult() {
|
|
61
|
+
return {
|
|
62
|
+
acknowledged: this.result.acknowledged,
|
|
63
|
+
insertedCount: this.result.insertedCount,
|
|
64
|
+
upsertedCount: this.result.upsertedCount,
|
|
65
|
+
matchedCount: this.result.matchedCount,
|
|
66
|
+
modifiedCount: this.result.modifiedCount,
|
|
67
|
+
deletedCount: this.result.deletedCount,
|
|
68
|
+
insertResults: this.result.insertResults,
|
|
69
|
+
updateResults: this.result.updateResults,
|
|
70
|
+
deleteResults: this.result.deleteResults
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Merge the results in the cursor to the existing result.
|
|
75
|
+
* @param currentBatchOffset - The offset index to the original models.
|
|
76
|
+
* @param response - The cursor response.
|
|
77
|
+
* @param documents - The documents in the cursor.
|
|
78
|
+
* @returns The current result.
|
|
79
|
+
*/
|
|
80
|
+
async merge(cursor) {
|
|
81
|
+
let writeConcernErrorResult;
|
|
82
|
+
try {
|
|
83
|
+
for await (const document of cursor) {
|
|
84
|
+
// Only add to maps if ok: 1
|
|
85
|
+
if (document.ok === 1) {
|
|
86
|
+
if (this.options.verboseResults) {
|
|
87
|
+
this.processDocument(cursor, document);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// If an individual write error is encountered during an ordered bulk write, drivers MUST
|
|
92
|
+
// record the error in writeErrors and immediately throw the exception. Otherwise, drivers
|
|
93
|
+
// MUST continue to iterate the results cursor and execute any further bulkWrite batches.
|
|
94
|
+
if (this.options.ordered) {
|
|
95
|
+
const error = new error_1.MongoClientBulkWriteError({
|
|
96
|
+
message: 'Mongo client ordered bulk write encountered a write error.'
|
|
97
|
+
});
|
|
98
|
+
error.writeErrors.set(document.idx + this.currentBatchOffset, {
|
|
99
|
+
code: document.code,
|
|
100
|
+
message: document.errmsg
|
|
101
|
+
});
|
|
102
|
+
error.partialResult = this.result;
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this.writeErrors.set(document.idx + this.currentBatchOffset, {
|
|
107
|
+
code: document.code,
|
|
108
|
+
message: document.errmsg
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof __1.MongoWriteConcernError) {
|
|
116
|
+
const result = error.result;
|
|
117
|
+
writeConcernErrorResult = {
|
|
118
|
+
insertedCount: result.nInserted,
|
|
119
|
+
upsertedCount: result.nUpserted,
|
|
120
|
+
matchedCount: result.nMatched,
|
|
121
|
+
modifiedCount: result.nModified,
|
|
122
|
+
deletedCount: result.nDeleted,
|
|
123
|
+
writeConcernError: result.writeConcernError
|
|
124
|
+
};
|
|
125
|
+
if (this.options.verboseResults && result.cursor.firstBatch) {
|
|
126
|
+
for (const document of result.cursor.firstBatch) {
|
|
127
|
+
if (document.ok === 1) {
|
|
128
|
+
this.processDocument(cursor, document);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
// Update the counts from the cursor response.
|
|
139
|
+
if (cursor.response) {
|
|
140
|
+
const response = cursor.response;
|
|
141
|
+
this.incrementCounts(response);
|
|
142
|
+
}
|
|
143
|
+
// Increment the batch offset.
|
|
144
|
+
this.currentBatchOffset += cursor.operations.length;
|
|
145
|
+
}
|
|
146
|
+
// If we have write concern errors ensure they are added.
|
|
147
|
+
if (writeConcernErrorResult) {
|
|
148
|
+
const writeConcernError = writeConcernErrorResult.writeConcernError;
|
|
149
|
+
this.incrementCounts(writeConcernErrorResult);
|
|
150
|
+
this.writeConcernErrors.push({
|
|
151
|
+
code: writeConcernError.code,
|
|
152
|
+
message: writeConcernError.errmsg
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return this.result;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Process an individual document in the results.
|
|
159
|
+
* @param cursor - The cursor.
|
|
160
|
+
* @param document - The document to process.
|
|
161
|
+
*/
|
|
162
|
+
processDocument(cursor, document) {
|
|
163
|
+
// Get the corresponding operation from the command.
|
|
164
|
+
const operation = cursor.operations[document.idx];
|
|
165
|
+
// Handle insert results.
|
|
166
|
+
if ('insert' in operation) {
|
|
167
|
+
this.result.insertResults?.set(document.idx + this.currentBatchOffset, {
|
|
168
|
+
insertedId: operation.document._id
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// Handle update results.
|
|
172
|
+
if ('update' in operation) {
|
|
173
|
+
const result = {
|
|
174
|
+
matchedCount: document.n,
|
|
175
|
+
modifiedCount: document.nModified ?? 0,
|
|
176
|
+
// Check if the bulk did actually upsert.
|
|
177
|
+
didUpsert: document.upserted != null
|
|
178
|
+
};
|
|
179
|
+
if (document.upserted) {
|
|
180
|
+
result.upsertedId = document.upserted._id;
|
|
181
|
+
}
|
|
182
|
+
this.result.updateResults?.set(document.idx + this.currentBatchOffset, result);
|
|
183
|
+
}
|
|
184
|
+
// Handle delete results.
|
|
185
|
+
if ('delete' in operation) {
|
|
186
|
+
this.result.deleteResults?.set(document.idx + this.currentBatchOffset, {
|
|
187
|
+
deletedCount: document.n
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Increment the result counts.
|
|
193
|
+
* @param document - The document with the results.
|
|
194
|
+
*/
|
|
195
|
+
incrementCounts(document) {
|
|
196
|
+
this.result.insertedCount += document.insertedCount;
|
|
197
|
+
this.result.upsertedCount += document.upsertedCount;
|
|
198
|
+
this.result.matchedCount += document.matchedCount;
|
|
199
|
+
this.result.modifiedCount += document.modifiedCount;
|
|
200
|
+
this.result.deletedCount += document.deletedCount;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.ClientBulkWriteResultsMerger = ClientBulkWriteResultsMerger;
|
|
204
|
+
//# sourceMappingURL=results_merger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results_merger.js","sourceRoot":"","sources":["../../../src/operations/client_bulk_write/results_merger.ts"],"names":[],"mappings":";;;AAAA,6BAA+C;AAG/C,uCAAwD;AAUxD;;GAEG;AACH,MAAM,cAAc,GAAG;IACrB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;C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AAC,GAAG,GAAG,IAAI,CAAC,kBAAkB,EAAE;gBACrE,YAAY,EAAE,QAAQ,CAAC,CAAC;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,eAAe,CAAC,QAAkB;QACxC,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,QAAQ,CAAC,YAAY,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,QAAQ,CAAC,YAAY,CAAC;IACpD,CAAC;CACF;AA5LD,oEA4LC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandOperation = void 0;
|
|
4
|
+
const constants_1 = require("../cmap/wire_protocol/constants");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const explain_1 = require("../explain");
|
|
7
|
+
const read_concern_1 = require("../read_concern");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const write_concern_1 = require("../write_concern");
|
|
10
|
+
const operation_1 = require("./operation");
|
|
11
|
+
/** @internal */
|
|
12
|
+
class CommandOperation extends operation_1.AbstractOperation {
|
|
13
|
+
constructor(parent, options) {
|
|
14
|
+
super(options);
|
|
15
|
+
this.options = options ?? {};
|
|
16
|
+
// NOTE: this was explicitly added for the add/remove user operations, it's likely
|
|
17
|
+
// something we'd want to reconsider. Perhaps those commands can use `Admin`
|
|
18
|
+
// as a parent?
|
|
19
|
+
const dbNameOverride = options?.dbName || options?.authdb;
|
|
20
|
+
if (dbNameOverride) {
|
|
21
|
+
this.ns = new utils_1.MongoDBNamespace(dbNameOverride, '$cmd');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.ns = parent
|
|
25
|
+
? parent.s.namespace.withCollection('$cmd')
|
|
26
|
+
: new utils_1.MongoDBNamespace('admin', '$cmd');
|
|
27
|
+
}
|
|
28
|
+
this.readConcern = read_concern_1.ReadConcern.fromOptions(options);
|
|
29
|
+
this.writeConcern = write_concern_1.WriteConcern.fromOptions(options);
|
|
30
|
+
if (this.hasAspect(operation_1.Aspect.EXPLAINABLE)) {
|
|
31
|
+
this.explain = explain_1.Explain.fromOptions(options);
|
|
32
|
+
if (this.explain)
|
|
33
|
+
(0, explain_1.validateExplainTimeoutOptions)(this.options, this.explain);
|
|
34
|
+
}
|
|
35
|
+
else if (options?.explain != null) {
|
|
36
|
+
throw new error_1.MongoInvalidArgumentError(`Option "explain" is not supported on this command`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
get canRetryWrite() {
|
|
40
|
+
if (this.hasAspect(operation_1.Aspect.EXPLAINABLE)) {
|
|
41
|
+
return this.explain == null;
|
|
42
|
+
}
|
|
43
|
+
return super.canRetryWrite;
|
|
44
|
+
}
|
|
45
|
+
buildOptions(timeoutContext) {
|
|
46
|
+
return {
|
|
47
|
+
...this.options,
|
|
48
|
+
...this.bsonOptions,
|
|
49
|
+
timeoutContext,
|
|
50
|
+
readPreference: this.readPreference,
|
|
51
|
+
session: this.session
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
buildCommand(connection, session) {
|
|
55
|
+
const command = this.buildCommandDocument(connection, session);
|
|
56
|
+
const inTransaction = this.session && this.session.inTransaction();
|
|
57
|
+
if (this.readConcern && (0, utils_1.commandSupportsReadConcern)(command) && !inTransaction) {
|
|
58
|
+
Object.assign(command, { readConcern: this.readConcern });
|
|
59
|
+
}
|
|
60
|
+
if (this.writeConcern && this.hasAspect(operation_1.Aspect.WRITE_OPERATION) && !inTransaction) {
|
|
61
|
+
write_concern_1.WriteConcern.apply(command, this.writeConcern);
|
|
62
|
+
}
|
|
63
|
+
if (this.options.collation &&
|
|
64
|
+
typeof this.options.collation === 'object' &&
|
|
65
|
+
!this.hasAspect(operation_1.Aspect.SKIP_COLLATION)) {
|
|
66
|
+
Object.assign(command, { collation: this.options.collation });
|
|
67
|
+
}
|
|
68
|
+
if (typeof this.options.maxTimeMS === 'number') {
|
|
69
|
+
command.maxTimeMS = this.options.maxTimeMS;
|
|
70
|
+
}
|
|
71
|
+
if (this.options.rawData != null &&
|
|
72
|
+
this.hasAspect(operation_1.Aspect.SUPPORTS_RAW_DATA) &&
|
|
73
|
+
(0, utils_1.maxWireVersion)(connection) >= constants_1.MIN_SUPPORTED_RAW_DATA_WIRE_VERSION) {
|
|
74
|
+
command.rawData = this.options.rawData;
|
|
75
|
+
}
|
|
76
|
+
if (this.hasAspect(operation_1.Aspect.EXPLAINABLE) && this.explain) {
|
|
77
|
+
return (0, explain_1.decorateWithExplain)(command, this.explain);
|
|
78
|
+
}
|
|
79
|
+
return command;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.CommandOperation = CommandOperation;
|
|
83
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/operations/command.ts"],"names":[],"mappings":";;;AAEA,+DAAsF;AACtF,oCAAqD;AACrD,wCAKoB;AACpB,kDAA8C;AAK9C,oCAAwF;AACxF,oDAA0E;AAE1E,2CAA+E;AA4D/E,gBAAgB;AAChB,MAAsB,gBAAoB,SAAQ,6BAAoB;IAMpE,YAAY,MAAwB,EAAE,OAAiC;QACrE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAE7B,kFAAkF;QAClF,kFAAkF;QAClF,qBAAqB;QACrB,MAAM,cAAc,GAAG,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC;QAC1D,IAAI,cAAc,EAAE,CAAC;YACnB,IAA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+CAAmC,EACjE,CAAC;YACD,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACzC,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,CAAC,kBAAM,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACvD,OAAO,IAAA,6BAAmB,EAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA3FD,4CA2FC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CountOperation = void 0;
|
|
4
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
5
|
+
const command_1 = require("./command");
|
|
6
|
+
const operation_1 = require("./operation");
|
|
7
|
+
/** @internal */
|
|
8
|
+
class CountOperation extends command_1.CommandOperation {
|
|
9
|
+
constructor(namespace, filter, options) {
|
|
10
|
+
super({ s: { namespace: namespace } }, options);
|
|
11
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.collectionName = namespace.collection;
|
|
14
|
+
this.query = filter;
|
|
15
|
+
}
|
|
16
|
+
get commandName() {
|
|
17
|
+
return 'count';
|
|
18
|
+
}
|
|
19
|
+
buildCommandDocument(_connection, _session) {
|
|
20
|
+
const options = this.options;
|
|
21
|
+
const cmd = {
|
|
22
|
+
count: this.collectionName,
|
|
23
|
+
query: this.query
|
|
24
|
+
};
|
|
25
|
+
if (typeof options.limit === 'number') {
|
|
26
|
+
cmd.limit = options.limit;
|
|
27
|
+
}
|
|
28
|
+
if (typeof options.skip === 'number') {
|
|
29
|
+
cmd.skip = options.skip;
|
|
30
|
+
}
|
|
31
|
+
if (options.hint != null) {
|
|
32
|
+
cmd.hint = options.hint;
|
|
33
|
+
}
|
|
34
|
+
if (typeof options.maxTimeMS === 'number') {
|
|
35
|
+
cmd.maxTimeMS = options.maxTimeMS;
|
|
36
|
+
}
|
|
37
|
+
return cmd;
|
|
38
|
+
}
|
|
39
|
+
handleOk(response) {
|
|
40
|
+
return response.getNumber('n') ?? 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.CountOperation = CountOperation;
|
|
44
|
+
(0, operation_1.defineAspects)(CountOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.RETRYABLE, operation_1.Aspect.SUPPORTS_RAW_DATA]);
|
|
45
|
+
//# sourceMappingURL=count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count.js","sourceRoot":"","sources":["../../src/operations/count.ts"],"names":[],"mappings":";;;AAEA,+DAAkE;AAIlE,uCAA2E;AAC3E,2CAAoD;AAgBpD,gBAAgB;AAChB,MAAa,cAAe,SAAQ,0BAAwB;IAM1D,YAAY,SAA2B,EAAE,MAAgB,EAAE,OAAqB;QAC9E,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAA2B,EAAE,OAAO,CAAC,CAAC;QANlE,iCAA4B,GAAG,2BAAe,CAAC;QAQtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,UAAU,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;IACtB,CAAC;IAED,IAAa,WAAW;QACtB,OAAO,OAAgB,CAAC;IAC1B,CAAC;IAEQ,oBAAoB,CAAC,WAAuB,EAAE,QAAwB;QAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,GAAG,GAAa;YACpB,KAAK,EAAE,IAAI,CAAC,cAAc;YAC1B,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;QAEF,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACtC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,CAAC;QAED,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACzB,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,CAAC;QAED,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC1C,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAEQ,QAAQ,CAAC,QAAgE;QAChF,OAAO,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF;AA/CD,wCA+CC;AAED,IAAA,yBAAa,EAAC,cAAc,EAAE,CAAC,kBAAM,CAAC,cAAc,EAAE,kBAAM,CAAC,SAAS,EAAE,kBAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateCollectionOperation = void 0;
|
|
4
|
+
exports.createCollections = createCollections;
|
|
5
|
+
const constants_1 = require("../cmap/wire_protocol/constants");
|
|
6
|
+
const responses_1 = require("../cmap/wire_protocol/responses");
|
|
7
|
+
const collection_1 = require("../collection");
|
|
8
|
+
const error_1 = require("../error");
|
|
9
|
+
const timeout_1 = require("../timeout");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const command_1 = require("./command");
|
|
12
|
+
const execute_operation_1 = require("./execute_operation");
|
|
13
|
+
const indexes_1 = require("./indexes");
|
|
14
|
+
const operation_1 = require("./operation");
|
|
15
|
+
const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
16
|
+
'w',
|
|
17
|
+
'wtimeout',
|
|
18
|
+
'timeoutMS',
|
|
19
|
+
'j',
|
|
20
|
+
'fsync',
|
|
21
|
+
'pkFactory',
|
|
22
|
+
'raw',
|
|
23
|
+
'readPreference',
|
|
24
|
+
'session',
|
|
25
|
+
'readConcern',
|
|
26
|
+
'writeConcern',
|
|
27
|
+
'raw',
|
|
28
|
+
'fieldsAsRaw',
|
|
29
|
+
'useBigInt64',
|
|
30
|
+
'promoteLongs',
|
|
31
|
+
'promoteValues',
|
|
32
|
+
'promoteBuffers',
|
|
33
|
+
'bsonRegExp',
|
|
34
|
+
'serializeFunctions',
|
|
35
|
+
'ignoreUndefined',
|
|
36
|
+
'enableUtf8Validation'
|
|
37
|
+
]);
|
|
38
|
+
/* @internal */
|
|
39
|
+
const INVALID_QE_VERSION = 'Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.';
|
|
40
|
+
/** @internal */
|
|
41
|
+
class CreateCollectionOperation extends command_1.CommandOperation {
|
|
42
|
+
constructor(db, name, options = {}) {
|
|
43
|
+
super(db, options);
|
|
44
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
|
|
45
|
+
this.options = options;
|
|
46
|
+
this.db = db;
|
|
47
|
+
this.name = name;
|
|
48
|
+
}
|
|
49
|
+
get commandName() {
|
|
50
|
+
return 'create';
|
|
51
|
+
}
|
|
52
|
+
buildCommandDocument(_connection, _session) {
|
|
53
|
+
const isOptionValid = ([k, v]) => v != null && typeof v !== 'function' && !ILLEGAL_COMMAND_FIELDS.has(k);
|
|
54
|
+
return {
|
|
55
|
+
create: this.name,
|
|
56
|
+
...Object.fromEntries(Object.entries(this.options).filter(isOptionValid))
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
handleOk(_response) {
|
|
60
|
+
return new collection_1.Collection(this.db, this.name, this.options);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.CreateCollectionOperation = CreateCollectionOperation;
|
|
64
|
+
async function createCollections(db, name, options) {
|
|
65
|
+
const timeoutContext = timeout_1.TimeoutContext.create({
|
|
66
|
+
session: options.session,
|
|
67
|
+
serverSelectionTimeoutMS: db.client.s.options.serverSelectionTimeoutMS,
|
|
68
|
+
waitQueueTimeoutMS: db.client.s.options.waitQueueTimeoutMS,
|
|
69
|
+
timeoutMS: options.timeoutMS
|
|
70
|
+
});
|
|
71
|
+
const encryptedFields = options.encryptedFields ??
|
|
72
|
+
db.client.s.options.autoEncryption?.encryptedFieldsMap?.[`${db.databaseName}.${name}`];
|
|
73
|
+
if (encryptedFields) {
|
|
74
|
+
class CreateSupportingFLEv2CollectionOperation extends CreateCollectionOperation {
|
|
75
|
+
buildCommandDocument(connection, session) {
|
|
76
|
+
if (!connection.description.loadBalanced &&
|
|
77
|
+
(0, utils_1.maxWireVersion)(connection) < constants_1.MIN_SUPPORTED_QE_WIRE_VERSION) {
|
|
78
|
+
throw new error_1.MongoCompatibilityError(`${INVALID_QE_VERSION} The minimum server version required is ${constants_1.MIN_SUPPORTED_QE_SERVER_VERSION}`);
|
|
79
|
+
}
|
|
80
|
+
return super.buildCommandDocument(connection, session);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Create auxilliary collections for queryable encryption support.
|
|
84
|
+
const escCollection = encryptedFields.escCollection ?? `enxcol_.${name}.esc`;
|
|
85
|
+
const ecocCollection = encryptedFields.ecocCollection ?? `enxcol_.${name}.ecoc`;
|
|
86
|
+
for (const collectionName of [escCollection, ecocCollection]) {
|
|
87
|
+
const createOp = new CreateSupportingFLEv2CollectionOperation(db, collectionName, {
|
|
88
|
+
clusteredIndex: {
|
|
89
|
+
key: { _id: 1 },
|
|
90
|
+
unique: true
|
|
91
|
+
},
|
|
92
|
+
session: options.session
|
|
93
|
+
});
|
|
94
|
+
await (0, execute_operation_1.executeOperation)(db.client, createOp, timeoutContext);
|
|
95
|
+
}
|
|
96
|
+
if (!options.encryptedFields) {
|
|
97
|
+
options = { ...options, encryptedFields };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const coll = await (0, execute_operation_1.executeOperation)(db.client, new CreateCollectionOperation(db, name, options), timeoutContext);
|
|
101
|
+
if (encryptedFields) {
|
|
102
|
+
// Create the required index for queryable encryption support.
|
|
103
|
+
const createIndexOp = indexes_1.CreateIndexesOperation.fromIndexSpecification(db, name, { __safeContent__: 1 }, { session: options.session });
|
|
104
|
+
await (0, execute_operation_1.executeOperation)(db.client, createIndexOp, timeoutContext);
|
|
105
|
+
}
|
|
106
|
+
return coll;
|
|
107
|
+
}
|
|
108
|
+
(0, operation_1.defineAspects)(CreateCollectionOperation, [operation_1.Aspect.WRITE_OPERATION]);
|
|
109
|
+
//# sourceMappingURL=create_collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_collection.js","sourceRoot":"","sources":["../../src/operations/create_collection.ts"],"names":[],"mappings":";;;AAiJA,8CAsEC;AArND,+DAGyC;AACzC,+DAAkE;AAClE,8CAA2C;AAE3C,oCAAmD;AAGnD,wCAA4C;AAC5C,oCAA0C;AAC1C,uCAA2E;AAC3E,2DAAuD;AACvD,uCAAmD;AACnD,2CAAoD;AAEpD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,GAAG;IACH,UAAU;IACV,WAAW;IACX,GAAG;IACH,OAAO;IACP,WAAW;IACX,KAAK;IACL,gBAAgB;IAChB,SAAS;IACT,aAAa;IACb,cAAc;IACd,KAAK;IACL,aAAa;IACb,aAAa;IACb,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,YAAY;IACZ,oBAAoB;IACpB,iBAAiB;IACjB,sBAAsB;CACvB,CAAC,CAAC;AAiEH,eAAe;AACf,MAAM,kBAAkB,GACtB,iHAAiH,CAAC;AAEpH,gBAAgB;AAChB,MAAa,yBAA0B,SAAQ,0BAA4B;IAMzE,YAAY,EAAM,EAAE,IAAY,EAAE,UAAmC,EAAE;QACrE,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