@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,171 @@
|
|
|
1
|
+
import { type Connection } from '..';
|
|
2
|
+
import type { BSONSerializeOptions, Document } from '../bson';
|
|
3
|
+
import { MIN_SUPPORTED_RAW_DATA_WIRE_VERSION } from '../cmap/wire_protocol/constants';
|
|
4
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
5
|
+
import {
|
|
6
|
+
decorateWithExplain,
|
|
7
|
+
Explain,
|
|
8
|
+
type ExplainOptions,
|
|
9
|
+
validateExplainTimeoutOptions
|
|
10
|
+
} from '../explain';
|
|
11
|
+
import { ReadConcern } from '../read_concern';
|
|
12
|
+
import type { ReadPreference } from '../read_preference';
|
|
13
|
+
import type { ServerCommandOptions } from '../sdam/server';
|
|
14
|
+
import type { ClientSession } from '../sessions';
|
|
15
|
+
import { type TimeoutContext } from '../timeout';
|
|
16
|
+
import { commandSupportsReadConcern, maxWireVersion, MongoDBNamespace } from '../utils';
|
|
17
|
+
import { WriteConcern, type WriteConcernOptions } from '../write_concern';
|
|
18
|
+
import type { ReadConcernLike } from './../read_concern';
|
|
19
|
+
import { AbstractOperation, Aspect, type OperationOptions } from './operation';
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export interface CollationOptions {
|
|
23
|
+
locale: string;
|
|
24
|
+
caseLevel?: boolean;
|
|
25
|
+
caseFirst?: string;
|
|
26
|
+
strength?: number;
|
|
27
|
+
numericOrdering?: boolean;
|
|
28
|
+
alternate?: string;
|
|
29
|
+
maxVariable?: string;
|
|
30
|
+
backwards?: boolean;
|
|
31
|
+
normalization?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @public */
|
|
35
|
+
export interface CommandOperationOptions
|
|
36
|
+
extends OperationOptions,
|
|
37
|
+
WriteConcernOptions,
|
|
38
|
+
ExplainOptions {
|
|
39
|
+
/** Specify a read concern and level for the collection. (only MongoDB 3.2 or higher supported) */
|
|
40
|
+
readConcern?: ReadConcernLike;
|
|
41
|
+
/** Collation */
|
|
42
|
+
collation?: CollationOptions;
|
|
43
|
+
/**
|
|
44
|
+
* maxTimeMS is a server-side time limit in milliseconds for processing an operation.
|
|
45
|
+
*/
|
|
46
|
+
maxTimeMS?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Comment to apply to the operation.
|
|
49
|
+
*
|
|
50
|
+
* In server versions pre-4.4, 'comment' must be string. A server
|
|
51
|
+
* error will be thrown if any other type is provided.
|
|
52
|
+
*
|
|
53
|
+
* In server versions 4.4 and above, 'comment' can be any valid BSON type.
|
|
54
|
+
*/
|
|
55
|
+
comment?: unknown;
|
|
56
|
+
// Admin command overrides.
|
|
57
|
+
dbName?: string;
|
|
58
|
+
authdb?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Used when the command needs to grant access to the underlying namespaces for time series collections.
|
|
62
|
+
* Only available on server versions 8.2 and above and is not meant for public use.
|
|
63
|
+
* @internal
|
|
64
|
+
* @sinceServerVersion 8.2
|
|
65
|
+
**/
|
|
66
|
+
rawData?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @internal */
|
|
70
|
+
export interface OperationParent {
|
|
71
|
+
s: { namespace: MongoDBNamespace };
|
|
72
|
+
readConcern?: ReadConcern;
|
|
73
|
+
writeConcern?: WriteConcern;
|
|
74
|
+
readPreference?: ReadPreference;
|
|
75
|
+
bsonOptions?: BSONSerializeOptions;
|
|
76
|
+
timeoutMS?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @internal */
|
|
80
|
+
export abstract class CommandOperation<T> extends AbstractOperation<T> {
|
|
81
|
+
override options: CommandOperationOptions;
|
|
82
|
+
readConcern?: ReadConcern;
|
|
83
|
+
writeConcern?: WriteConcern;
|
|
84
|
+
explain?: Explain;
|
|
85
|
+
|
|
86
|
+
constructor(parent?: OperationParent, options?: CommandOperationOptions) {
|
|
87
|
+
super(options);
|
|
88
|
+
this.options = options ?? {};
|
|
89
|
+
|
|
90
|
+
// NOTE: this was explicitly added for the add/remove user operations, it's likely
|
|
91
|
+
// something we'd want to reconsider. Perhaps those commands can use `Admin`
|
|
92
|
+
// as a parent?
|
|
93
|
+
const dbNameOverride = options?.dbName || options?.authdb;
|
|
94
|
+
if (dbNameOverride) {
|
|
95
|
+
this.ns = new MongoDBNamespace(dbNameOverride, '$cmd');
|
|
96
|
+
} else {
|
|
97
|
+
this.ns = parent
|
|
98
|
+
? parent.s.namespace.withCollection('$cmd')
|
|
99
|
+
: new MongoDBNamespace('admin', '$cmd');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.readConcern = ReadConcern.fromOptions(options);
|
|
103
|
+
this.writeConcern = WriteConcern.fromOptions(options);
|
|
104
|
+
|
|
105
|
+
if (this.hasAspect(Aspect.EXPLAINABLE)) {
|
|
106
|
+
this.explain = Explain.fromOptions(options);
|
|
107
|
+
if (this.explain) validateExplainTimeoutOptions(this.options, this.explain);
|
|
108
|
+
} else if (options?.explain != null) {
|
|
109
|
+
throw new MongoInvalidArgumentError(`Option "explain" is not supported on this command`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
override get canRetryWrite(): boolean {
|
|
114
|
+
if (this.hasAspect(Aspect.EXPLAINABLE)) {
|
|
115
|
+
return this.explain == null;
|
|
116
|
+
}
|
|
117
|
+
return super.canRetryWrite;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
abstract buildCommandDocument(connection: Connection, session?: ClientSession): Document;
|
|
121
|
+
|
|
122
|
+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
123
|
+
return {
|
|
124
|
+
...this.options,
|
|
125
|
+
...this.bsonOptions,
|
|
126
|
+
timeoutContext,
|
|
127
|
+
readPreference: this.readPreference,
|
|
128
|
+
session: this.session
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
override buildCommand(connection: Connection, session?: ClientSession): Document {
|
|
133
|
+
const command = this.buildCommandDocument(connection, session);
|
|
134
|
+
|
|
135
|
+
const inTransaction = this.session && this.session.inTransaction();
|
|
136
|
+
|
|
137
|
+
if (this.readConcern && commandSupportsReadConcern(command) && !inTransaction) {
|
|
138
|
+
Object.assign(command, { readConcern: this.readConcern });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (this.writeConcern && this.hasAspect(Aspect.WRITE_OPERATION) && !inTransaction) {
|
|
142
|
+
WriteConcern.apply(command, this.writeConcern);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (
|
|
146
|
+
this.options.collation &&
|
|
147
|
+
typeof this.options.collation === 'object' &&
|
|
148
|
+
!this.hasAspect(Aspect.SKIP_COLLATION)
|
|
149
|
+
) {
|
|
150
|
+
Object.assign(command, { collation: this.options.collation });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (typeof this.options.maxTimeMS === 'number') {
|
|
154
|
+
command.maxTimeMS = this.options.maxTimeMS;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (
|
|
158
|
+
this.options.rawData != null &&
|
|
159
|
+
this.hasAspect(Aspect.SUPPORTS_RAW_DATA) &&
|
|
160
|
+
maxWireVersion(connection) >= MIN_SUPPORTED_RAW_DATA_WIRE_VERSION
|
|
161
|
+
) {
|
|
162
|
+
command.rawData = this.options.rawData;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (this.hasAspect(Aspect.EXPLAINABLE) && this.explain) {
|
|
166
|
+
return decorateWithExplain(command, this.explain);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return command;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type Connection } from '..';
|
|
2
|
+
import type { Document } from '../bson';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import type { Collection } from '../collection';
|
|
5
|
+
import type { ClientSession } from '../sessions';
|
|
6
|
+
import type { MongoDBNamespace } from '../utils';
|
|
7
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
8
|
+
import { Aspect, defineAspects } from './operation';
|
|
9
|
+
|
|
10
|
+
/** @public */
|
|
11
|
+
export interface CountOptions extends CommandOperationOptions {
|
|
12
|
+
/** The number of documents to skip. */
|
|
13
|
+
skip?: number;
|
|
14
|
+
/** The maximum amounts to count before aborting. */
|
|
15
|
+
limit?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Number of milliseconds to wait before aborting the query.
|
|
18
|
+
*/
|
|
19
|
+
maxTimeMS?: number;
|
|
20
|
+
/** An index name hint for the query. */
|
|
21
|
+
hint?: string | Document;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
export class CountOperation extends CommandOperation<number> {
|
|
26
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
27
|
+
override options: CountOptions;
|
|
28
|
+
collectionName?: string;
|
|
29
|
+
query: Document;
|
|
30
|
+
|
|
31
|
+
constructor(namespace: MongoDBNamespace, filter: Document, options: CountOptions) {
|
|
32
|
+
super({ s: { namespace: namespace } } as unknown as Collection, options);
|
|
33
|
+
|
|
34
|
+
this.options = options;
|
|
35
|
+
this.collectionName = namespace.collection;
|
|
36
|
+
this.query = filter;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override get commandName() {
|
|
40
|
+
return 'count' as const;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
|
|
44
|
+
const options = this.options;
|
|
45
|
+
const cmd: Document = {
|
|
46
|
+
count: this.collectionName,
|
|
47
|
+
query: this.query
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (typeof options.limit === 'number') {
|
|
51
|
+
cmd.limit = options.limit;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof options.skip === 'number') {
|
|
55
|
+
cmd.skip = options.skip;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (options.hint != null) {
|
|
59
|
+
cmd.hint = options.hint;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof options.maxTimeMS === 'number') {
|
|
63
|
+
cmd.maxTimeMS = options.maxTimeMS;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return cmd;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): number {
|
|
70
|
+
return response.getNumber('n') ?? 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
defineAspects(CountOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.SUPPORTS_RAW_DATA]);
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { type Connection } from '..';
|
|
2
|
+
import type { Document } from '../bson';
|
|
3
|
+
import {
|
|
4
|
+
MIN_SUPPORTED_QE_SERVER_VERSION,
|
|
5
|
+
MIN_SUPPORTED_QE_WIRE_VERSION
|
|
6
|
+
} from '../cmap/wire_protocol/constants';
|
|
7
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
8
|
+
import { Collection } from '../collection';
|
|
9
|
+
import type { Db } from '../db';
|
|
10
|
+
import { MongoCompatibilityError } from '../error';
|
|
11
|
+
import type { PkFactory } from '../mongo_client';
|
|
12
|
+
import type { ClientSession } from '../sessions';
|
|
13
|
+
import { TimeoutContext } from '../timeout';
|
|
14
|
+
import { maxWireVersion } from '../utils';
|
|
15
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
16
|
+
import { executeOperation } from './execute_operation';
|
|
17
|
+
import { CreateIndexesOperation } from './indexes';
|
|
18
|
+
import { Aspect, defineAspects } from './operation';
|
|
19
|
+
|
|
20
|
+
const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
21
|
+
'w',
|
|
22
|
+
'wtimeout',
|
|
23
|
+
'timeoutMS',
|
|
24
|
+
'j',
|
|
25
|
+
'fsync',
|
|
26
|
+
'pkFactory',
|
|
27
|
+
'raw',
|
|
28
|
+
'readPreference',
|
|
29
|
+
'session',
|
|
30
|
+
'readConcern',
|
|
31
|
+
'writeConcern',
|
|
32
|
+
'raw',
|
|
33
|
+
'fieldsAsRaw',
|
|
34
|
+
'useBigInt64',
|
|
35
|
+
'promoteLongs',
|
|
36
|
+
'promoteValues',
|
|
37
|
+
'promoteBuffers',
|
|
38
|
+
'bsonRegExp',
|
|
39
|
+
'serializeFunctions',
|
|
40
|
+
'ignoreUndefined',
|
|
41
|
+
'enableUtf8Validation'
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
/** @public
|
|
45
|
+
* Configuration options for timeseries collections
|
|
46
|
+
* @see https://www.mongodb.com/docs/manual/core/timeseries-collections/
|
|
47
|
+
*/
|
|
48
|
+
export interface TimeSeriesCollectionOptions extends Document {
|
|
49
|
+
timeField: string;
|
|
50
|
+
metaField?: string;
|
|
51
|
+
granularity?: 'seconds' | 'minutes' | 'hours' | string;
|
|
52
|
+
bucketMaxSpanSeconds?: number;
|
|
53
|
+
bucketRoundingSeconds?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @public
|
|
57
|
+
* Configuration options for clustered collections
|
|
58
|
+
* @see https://www.mongodb.com/docs/manual/core/clustered-collections/
|
|
59
|
+
*/
|
|
60
|
+
export interface ClusteredCollectionOptions extends Document {
|
|
61
|
+
name?: string;
|
|
62
|
+
key: Document;
|
|
63
|
+
unique: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @public */
|
|
67
|
+
export interface CreateCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
|
|
68
|
+
/** Create a capped collection */
|
|
69
|
+
capped?: boolean;
|
|
70
|
+
/** The size of the capped collection in bytes */
|
|
71
|
+
size?: number;
|
|
72
|
+
/** The maximum number of documents in the capped collection */
|
|
73
|
+
max?: number;
|
|
74
|
+
/** Available for the MMAPv1 storage engine only to set the usePowerOf2Sizes and the noPadding flag */
|
|
75
|
+
flags?: number;
|
|
76
|
+
/** Allows users to specify configuration to the storage engine on a per-collection basis when creating a collection */
|
|
77
|
+
storageEngine?: Document;
|
|
78
|
+
/** Allows users to specify validation rules or expressions for the collection. For more information, see Document Validation */
|
|
79
|
+
validator?: Document;
|
|
80
|
+
/** Determines how strictly MongoDB applies the validation rules to existing documents during an update */
|
|
81
|
+
validationLevel?: string;
|
|
82
|
+
/** Determines whether to error on invalid documents or just warn about the violations but allow invalid documents to be inserted */
|
|
83
|
+
validationAction?: string;
|
|
84
|
+
/** Allows users to specify a default configuration for indexes when creating a collection */
|
|
85
|
+
indexOptionDefaults?: Document;
|
|
86
|
+
/** The name of the source collection or view from which to create the view. The name is not the full namespace of the collection or view (i.e., does not include the database name and implies the same database as the view to create) */
|
|
87
|
+
viewOn?: string;
|
|
88
|
+
/** An array that consists of the aggregation pipeline stage. Creates the view by applying the specified pipeline to the viewOn collection or view */
|
|
89
|
+
pipeline?: Document[];
|
|
90
|
+
/** A primary key factory function for generation of custom _id keys. */
|
|
91
|
+
pkFactory?: PkFactory;
|
|
92
|
+
/** A document specifying configuration options for timeseries collections. */
|
|
93
|
+
timeseries?: TimeSeriesCollectionOptions;
|
|
94
|
+
/** A document specifying configuration options for clustered collections. For MongoDB 5.3 and above. */
|
|
95
|
+
clusteredIndex?: ClusteredCollectionOptions;
|
|
96
|
+
/** The number of seconds after which a document in a timeseries or clustered collection expires. */
|
|
97
|
+
expireAfterSeconds?: number;
|
|
98
|
+
/** @experimental */
|
|
99
|
+
encryptedFields?: Document;
|
|
100
|
+
/**
|
|
101
|
+
* If set, enables pre-update and post-update document events to be included for any
|
|
102
|
+
* change streams that listen on this collection.
|
|
103
|
+
*/
|
|
104
|
+
changeStreamPreAndPostImages?: { enabled: boolean };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* @internal */
|
|
108
|
+
const INVALID_QE_VERSION =
|
|
109
|
+
'Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.';
|
|
110
|
+
|
|
111
|
+
/** @internal */
|
|
112
|
+
export class CreateCollectionOperation extends CommandOperation<Collection> {
|
|
113
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
114
|
+
override options: CreateCollectionOptions;
|
|
115
|
+
db: Db;
|
|
116
|
+
name: string;
|
|
117
|
+
|
|
118
|
+
constructor(db: Db, name: string, options: CreateCollectionOptions = {}) {
|
|
119
|
+
super(db, options);
|
|
120
|
+
|
|
121
|
+
this.options = options;
|
|
122
|
+
this.db = db;
|
|
123
|
+
this.name = name;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override get commandName() {
|
|
127
|
+
return 'create' as const;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
|
|
131
|
+
const isOptionValid = ([k, v]: [k: string, v: unknown]) =>
|
|
132
|
+
v != null && typeof v !== 'function' && !ILLEGAL_COMMAND_FIELDS.has(k);
|
|
133
|
+
return {
|
|
134
|
+
create: this.name,
|
|
135
|
+
...Object.fromEntries(Object.entries(this.options).filter(isOptionValid))
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
override handleOk(
|
|
140
|
+
_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
141
|
+
): Collection<Document> {
|
|
142
|
+
return new Collection(this.db, this.name, this.options);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function createCollections<TSchema extends Document>(
|
|
147
|
+
db: Db,
|
|
148
|
+
name: string,
|
|
149
|
+
options: CreateCollectionOptions
|
|
150
|
+
): Promise<Collection<TSchema>> {
|
|
151
|
+
const timeoutContext = TimeoutContext.create({
|
|
152
|
+
session: options.session,
|
|
153
|
+
serverSelectionTimeoutMS: db.client.s.options.serverSelectionTimeoutMS,
|
|
154
|
+
waitQueueTimeoutMS: db.client.s.options.waitQueueTimeoutMS,
|
|
155
|
+
timeoutMS: options.timeoutMS
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const encryptedFields: Document | undefined =
|
|
159
|
+
options.encryptedFields ??
|
|
160
|
+
db.client.s.options.autoEncryption?.encryptedFieldsMap?.[`${db.databaseName}.${name}`];
|
|
161
|
+
|
|
162
|
+
if (encryptedFields) {
|
|
163
|
+
class CreateSupportingFLEv2CollectionOperation extends CreateCollectionOperation {
|
|
164
|
+
override buildCommandDocument(connection: Connection, session?: ClientSession): Document {
|
|
165
|
+
if (
|
|
166
|
+
!connection.description.loadBalanced &&
|
|
167
|
+
maxWireVersion(connection) < MIN_SUPPORTED_QE_WIRE_VERSION
|
|
168
|
+
) {
|
|
169
|
+
throw new MongoCompatibilityError(
|
|
170
|
+
`${INVALID_QE_VERSION} The minimum server version required is ${MIN_SUPPORTED_QE_SERVER_VERSION}`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return super.buildCommandDocument(connection, session);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Create auxilliary collections for queryable encryption support.
|
|
179
|
+
const escCollection = encryptedFields.escCollection ?? `enxcol_.${name}.esc`;
|
|
180
|
+
const ecocCollection = encryptedFields.ecocCollection ?? `enxcol_.${name}.ecoc`;
|
|
181
|
+
|
|
182
|
+
for (const collectionName of [escCollection, ecocCollection]) {
|
|
183
|
+
const createOp = new CreateSupportingFLEv2CollectionOperation(db, collectionName, {
|
|
184
|
+
clusteredIndex: {
|
|
185
|
+
key: { _id: 1 },
|
|
186
|
+
unique: true
|
|
187
|
+
},
|
|
188
|
+
session: options.session
|
|
189
|
+
});
|
|
190
|
+
await executeOperation(db.client, createOp, timeoutContext);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!options.encryptedFields) {
|
|
194
|
+
options = { ...options, encryptedFields };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const coll = await executeOperation(
|
|
199
|
+
db.client,
|
|
200
|
+
new CreateCollectionOperation(db, name, options),
|
|
201
|
+
timeoutContext
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (encryptedFields) {
|
|
205
|
+
// Create the required index for queryable encryption support.
|
|
206
|
+
const createIndexOp = CreateIndexesOperation.fromIndexSpecification(
|
|
207
|
+
db,
|
|
208
|
+
name,
|
|
209
|
+
{ __safeContent__: 1 },
|
|
210
|
+
{ session: options.session }
|
|
211
|
+
);
|
|
212
|
+
await executeOperation(db.client, createIndexOp, timeoutContext);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return coll as unknown as Collection<TSchema>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
defineAspects(CreateCollectionOperation, [Aspect.WRITE_OPERATION]);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import { MongoCompatibilityError, MongoServerError } from '../error';
|
|
5
|
+
import type { ClientSession } from '../sessions';
|
|
6
|
+
import { maxWireVersion, type MongoDBCollectionNamespace, type MongoDBNamespace } from '../utils';
|
|
7
|
+
import { type WriteConcernOptions } from '../write_concern';
|
|
8
|
+
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
|
|
9
|
+
import { Aspect, defineAspects, type Hint } from './operation';
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export interface DeleteOptions extends CommandOperationOptions, WriteConcernOptions {
|
|
13
|
+
/** If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. */
|
|
14
|
+
ordered?: boolean;
|
|
15
|
+
/** Specifies the collation to use for the operation */
|
|
16
|
+
collation?: CollationOptions;
|
|
17
|
+
/** Specify that the update query should only consider plans using the hinted index */
|
|
18
|
+
hint?: string | Document;
|
|
19
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
20
|
+
let?: Document;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @public */
|
|
24
|
+
export interface DeleteResult {
|
|
25
|
+
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined. */
|
|
26
|
+
acknowledged: boolean;
|
|
27
|
+
/** The number of documents that were deleted */
|
|
28
|
+
deletedCount: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @public */
|
|
32
|
+
export interface DeleteStatement {
|
|
33
|
+
/** The query that matches documents to delete. */
|
|
34
|
+
q: Document;
|
|
35
|
+
/** The number of matching documents to delete. */
|
|
36
|
+
limit: number;
|
|
37
|
+
/** Specifies the collation to use for the operation. */
|
|
38
|
+
collation?: CollationOptions;
|
|
39
|
+
/** A document or string that specifies the index to use to support the query predicate. */
|
|
40
|
+
hint?: Hint;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
export class DeleteOperation extends CommandOperation<Document> {
|
|
45
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
46
|
+
override options: DeleteOptions;
|
|
47
|
+
statements: DeleteStatement[];
|
|
48
|
+
|
|
49
|
+
constructor(ns: MongoDBNamespace, statements: DeleteStatement[], options: DeleteOptions) {
|
|
50
|
+
super(undefined, options);
|
|
51
|
+
this.options = options;
|
|
52
|
+
this.ns = ns;
|
|
53
|
+
this.statements = statements;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override get commandName() {
|
|
57
|
+
return 'delete' as const;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override get canRetryWrite(): boolean {
|
|
61
|
+
if (super.canRetryWrite === false) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.statements.every(op => (op.limit != null ? op.limit > 0 : true));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override buildCommandDocument(connection: Connection, _session?: ClientSession): Document {
|
|
69
|
+
const options = this.options;
|
|
70
|
+
|
|
71
|
+
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
|
|
72
|
+
const command: Document = {
|
|
73
|
+
delete: this.ns.collection,
|
|
74
|
+
deletes: this.statements,
|
|
75
|
+
ordered
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (options.let) {
|
|
79
|
+
command.let = options.let;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// we check for undefined specifically here to allow falsy values
|
|
83
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
84
|
+
if (options.comment !== undefined) {
|
|
85
|
+
command.comment = options.comment;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
|
|
89
|
+
if (unacknowledgedWrite && maxWireVersion(connection) < 9) {
|
|
90
|
+
if (this.statements.find((o: Document) => o.hint)) {
|
|
91
|
+
throw new MongoCompatibilityError(
|
|
92
|
+
`hint for the delete command is only supported on MongoDB 4.4+`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return command;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class DeleteOneOperation extends DeleteOperation {
|
|
102
|
+
constructor(ns: MongoDBCollectionNamespace, filter: Document, options: DeleteOptions) {
|
|
103
|
+
super(ns, [makeDeleteStatement(filter, { ...options, limit: 1 })], options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
override handleOk(
|
|
107
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
108
|
+
): DeleteResult {
|
|
109
|
+
const res = super.handleOk(response);
|
|
110
|
+
|
|
111
|
+
// @ts-expect-error Explain commands have broken TS
|
|
112
|
+
if (this.explain) return res;
|
|
113
|
+
|
|
114
|
+
if (res.code) throw new MongoServerError(res);
|
|
115
|
+
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
119
|
+
deletedCount: res.n
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export class DeleteManyOperation extends DeleteOperation {
|
|
124
|
+
constructor(ns: MongoDBCollectionNamespace, filter: Document, options: DeleteOptions) {
|
|
125
|
+
super(ns, [makeDeleteStatement(filter, options)], options);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override handleOk(
|
|
129
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
130
|
+
): DeleteResult {
|
|
131
|
+
const res = super.handleOk(response);
|
|
132
|
+
|
|
133
|
+
// @ts-expect-error Explain commands have broken TS
|
|
134
|
+
if (this.explain) return res;
|
|
135
|
+
|
|
136
|
+
if (res.code) throw new MongoServerError(res);
|
|
137
|
+
if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
141
|
+
deletedCount: res.n
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function makeDeleteStatement(
|
|
147
|
+
filter: Document,
|
|
148
|
+
options: DeleteOptions & { limit?: number }
|
|
149
|
+
): DeleteStatement {
|
|
150
|
+
const op: DeleteStatement = {
|
|
151
|
+
q: filter,
|
|
152
|
+
limit: typeof options.limit === 'number' ? options.limit : 0
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
if (options.collation) {
|
|
156
|
+
op.collation = options.collation;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (options.hint) {
|
|
160
|
+
op.hint = options.hint;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return op;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
defineAspects(DeleteOperation, [
|
|
167
|
+
Aspect.RETRYABLE,
|
|
168
|
+
Aspect.WRITE_OPERATION,
|
|
169
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
170
|
+
]);
|
|
171
|
+
defineAspects(DeleteOneOperation, [
|
|
172
|
+
Aspect.RETRYABLE,
|
|
173
|
+
Aspect.WRITE_OPERATION,
|
|
174
|
+
Aspect.EXPLAINABLE,
|
|
175
|
+
Aspect.SKIP_COLLATION,
|
|
176
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
177
|
+
]);
|
|
178
|
+
defineAspects(DeleteManyOperation, [
|
|
179
|
+
Aspect.WRITE_OPERATION,
|
|
180
|
+
Aspect.EXPLAINABLE,
|
|
181
|
+
Aspect.SKIP_COLLATION,
|
|
182
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
183
|
+
]);
|