@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,245 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import { MongoAPIError } from '../error';
|
|
3
|
+
import {
|
|
4
|
+
Explain,
|
|
5
|
+
type ExplainCommandOptions,
|
|
6
|
+
type ExplainVerbosityLike,
|
|
7
|
+
validateExplainTimeoutOptions
|
|
8
|
+
} from '../explain';
|
|
9
|
+
import type { MongoClient } from '../mongo_client';
|
|
10
|
+
import { type Abortable } from '../mongo_types';
|
|
11
|
+
import { AggregateOperation, type AggregateOptions } from '../operations/aggregate';
|
|
12
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
13
|
+
import type { ClientSession } from '../sessions';
|
|
14
|
+
import type { Sort } from '../sort';
|
|
15
|
+
import { mergeOptions, type MongoDBNamespace } from '../utils';
|
|
16
|
+
import {
|
|
17
|
+
type AbstractCursorOptions,
|
|
18
|
+
CursorTimeoutMode,
|
|
19
|
+
type InitialCursorResponse
|
|
20
|
+
} from './abstract_cursor';
|
|
21
|
+
import { ExplainableCursor } from './explainable_cursor';
|
|
22
|
+
|
|
23
|
+
/** @public */
|
|
24
|
+
export interface AggregationCursorOptions extends AbstractCursorOptions, AggregateOptions {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
|
|
28
|
+
* allowing for iteration over the results returned from the underlying query. It supports
|
|
29
|
+
* one by one document iteration, conversion to an array or can be iterated as a Node 4.X
|
|
30
|
+
* or higher stream
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export class AggregationCursor<TSchema = any> extends ExplainableCursor<TSchema> {
|
|
34
|
+
public readonly pipeline: Document[];
|
|
35
|
+
/** @internal */
|
|
36
|
+
private aggregateOptions: AggregateOptions & Abortable;
|
|
37
|
+
|
|
38
|
+
/** @internal */
|
|
39
|
+
constructor(
|
|
40
|
+
client: MongoClient,
|
|
41
|
+
namespace: MongoDBNamespace,
|
|
42
|
+
pipeline: Document[] = [],
|
|
43
|
+
options: AggregateOptions & Abortable = {}
|
|
44
|
+
) {
|
|
45
|
+
super(client, namespace, options);
|
|
46
|
+
|
|
47
|
+
this.pipeline = pipeline;
|
|
48
|
+
this.aggregateOptions = options;
|
|
49
|
+
|
|
50
|
+
const lastStage: Document | undefined = this.pipeline[this.pipeline.length - 1];
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
this.cursorOptions.timeoutMS != null &&
|
|
54
|
+
this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION &&
|
|
55
|
+
(lastStage?.$merge != null || lastStage?.$out != null)
|
|
56
|
+
)
|
|
57
|
+
throw new MongoAPIError('Cannot use $out or $merge stage with ITERATION timeoutMode');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
clone(): AggregationCursor<TSchema> {
|
|
61
|
+
const clonedOptions = mergeOptions({}, this.aggregateOptions);
|
|
62
|
+
delete clonedOptions.session;
|
|
63
|
+
return new AggregationCursor(this.client, this.namespace, this.pipeline, {
|
|
64
|
+
...clonedOptions
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override map<T>(transform: (doc: TSchema) => T): AggregationCursor<T> {
|
|
69
|
+
return super.map(transform) as AggregationCursor<T>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @internal */
|
|
73
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
74
|
+
const options = {
|
|
75
|
+
...this.aggregateOptions,
|
|
76
|
+
...this.cursorOptions,
|
|
77
|
+
session,
|
|
78
|
+
signal: this.signal
|
|
79
|
+
};
|
|
80
|
+
if (options.explain) {
|
|
81
|
+
try {
|
|
82
|
+
validateExplainTimeoutOptions(options, Explain.fromOptions(options));
|
|
83
|
+
} catch {
|
|
84
|
+
throw new MongoAPIError(
|
|
85
|
+
'timeoutMS cannot be used with explain when explain is specified in aggregateOptions'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, options);
|
|
91
|
+
|
|
92
|
+
const response = await executeOperation(this.client, aggregateOperation, this.timeoutContext);
|
|
93
|
+
|
|
94
|
+
return { server: aggregateOperation.server, session, response };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Execute the explain for the cursor */
|
|
98
|
+
async explain(): Promise<Document>;
|
|
99
|
+
async explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
|
|
100
|
+
async explain(options: { timeoutMS?: number }): Promise<Document>;
|
|
101
|
+
async explain(
|
|
102
|
+
verbosity: ExplainVerbosityLike | ExplainCommandOptions,
|
|
103
|
+
options: { timeoutMS?: number }
|
|
104
|
+
): Promise<Document>;
|
|
105
|
+
async explain(
|
|
106
|
+
verbosity?: ExplainVerbosityLike | ExplainCommandOptions | { timeoutMS?: number },
|
|
107
|
+
options?: { timeoutMS?: number }
|
|
108
|
+
): Promise<Document> {
|
|
109
|
+
const { explain, timeout } = this.resolveExplainTimeoutOptions(verbosity, options);
|
|
110
|
+
return (
|
|
111
|
+
await executeOperation(
|
|
112
|
+
this.client,
|
|
113
|
+
new AggregateOperation(this.namespace, this.pipeline, {
|
|
114
|
+
...this.aggregateOptions, // NOTE: order matters here, we may need to refine this
|
|
115
|
+
...this.cursorOptions,
|
|
116
|
+
...timeout,
|
|
117
|
+
explain: explain ?? true
|
|
118
|
+
})
|
|
119
|
+
)
|
|
120
|
+
).shift(this.deserializationOptions);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Add a stage to the aggregation pipeline
|
|
124
|
+
* @example
|
|
125
|
+
* ```
|
|
126
|
+
* const documents = await users.aggregate().addStage({ $match: { name: /Mike/ } }).toArray();
|
|
127
|
+
* ```
|
|
128
|
+
* @example
|
|
129
|
+
* ```
|
|
130
|
+
* const documents = await users.aggregate()
|
|
131
|
+
* .addStage<{ name: string }>({ $project: { name: true } })
|
|
132
|
+
* .toArray(); // type of documents is { name: string }[]
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
addStage(stage: Document): this;
|
|
136
|
+
addStage<T = Document>(stage: Document): AggregationCursor<T>;
|
|
137
|
+
addStage<T = Document>(stage: Document): AggregationCursor<T> {
|
|
138
|
+
this.throwIfInitialized();
|
|
139
|
+
if (
|
|
140
|
+
this.cursorOptions.timeoutMS != null &&
|
|
141
|
+
this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION &&
|
|
142
|
+
(stage.$out != null || stage.$merge != null)
|
|
143
|
+
) {
|
|
144
|
+
throw new MongoAPIError('Cannot use $out or $merge stage with ITERATION timeoutMode');
|
|
145
|
+
}
|
|
146
|
+
this.pipeline.push(stage);
|
|
147
|
+
return this as unknown as AggregationCursor<T>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Add a group stage to the aggregation pipeline */
|
|
151
|
+
group<T = TSchema>($group: Document): AggregationCursor<T>;
|
|
152
|
+
group($group: Document): this {
|
|
153
|
+
return this.addStage({ $group });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Add a limit stage to the aggregation pipeline */
|
|
157
|
+
limit($limit: number): this {
|
|
158
|
+
return this.addStage({ $limit });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Add a match stage to the aggregation pipeline */
|
|
162
|
+
match($match: Document): this {
|
|
163
|
+
return this.addStage({ $match });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Add an out stage to the aggregation pipeline */
|
|
167
|
+
out($out: { db: string; coll: string } | string): this {
|
|
168
|
+
return this.addStage({ $out });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Add a project stage to the aggregation pipeline
|
|
173
|
+
*
|
|
174
|
+
* @remarks
|
|
175
|
+
* In order to strictly type this function you must provide an interface
|
|
176
|
+
* that represents the effect of your projection on the result documents.
|
|
177
|
+
*
|
|
178
|
+
* By default chaining a projection to your cursor changes the returned type to the generic {@link Document} type.
|
|
179
|
+
* You should specify a parameterized type to have assertions on your final results.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* // Best way
|
|
184
|
+
* const docs: AggregationCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
|
|
185
|
+
* // Flexible way
|
|
186
|
+
* const docs: AggregationCursor<Document> = cursor.project({ _id: 0, a: true });
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* In order to strictly type this function you must provide an interface
|
|
191
|
+
* that represents the effect of your projection on the result documents.
|
|
192
|
+
*
|
|
193
|
+
* **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
|
|
194
|
+
* it **does not** return a new instance of a cursor. This means when calling project,
|
|
195
|
+
* you should always assign the result to a new variable in order to get a correctly typed cursor variable.
|
|
196
|
+
* Take note of the following example:
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const cursor: AggregationCursor<{ a: number; b: string }> = coll.aggregate([]);
|
|
201
|
+
* const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
|
|
202
|
+
* const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
|
|
203
|
+
*
|
|
204
|
+
* // or always use chaining and save the final cursor
|
|
205
|
+
*
|
|
206
|
+
* const cursor = coll.aggregate().project<{ a: string }>({
|
|
207
|
+
* _id: 0,
|
|
208
|
+
* a: { $convert: { input: '$a', to: 'string' }
|
|
209
|
+
* }});
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
project<T extends Document = Document>($project: Document): AggregationCursor<T> {
|
|
213
|
+
return this.addStage<T>({ $project });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Add a lookup stage to the aggregation pipeline */
|
|
217
|
+
lookup($lookup: Document): this {
|
|
218
|
+
return this.addStage({ $lookup });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Add a redact stage to the aggregation pipeline */
|
|
222
|
+
redact($redact: Document): this {
|
|
223
|
+
return this.addStage({ $redact });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Add a skip stage to the aggregation pipeline */
|
|
227
|
+
skip($skip: number): this {
|
|
228
|
+
return this.addStage({ $skip });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Add a sort stage to the aggregation pipeline */
|
|
232
|
+
sort($sort: Sort): this {
|
|
233
|
+
return this.addStage({ $sort });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Add a unwind stage to the aggregation pipeline */
|
|
237
|
+
unwind($unwind: Document | string): this {
|
|
238
|
+
return this.addStage({ $unwind });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Add a geoNear stage to the aggregation pipeline */
|
|
242
|
+
geoNear($geoNear: Document): this {
|
|
243
|
+
return this.addStage({ $geoNear });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import {
|
|
3
|
+
ChangeStream,
|
|
4
|
+
type ChangeStreamDocument,
|
|
5
|
+
type ChangeStreamEvents,
|
|
6
|
+
type OperationTime,
|
|
7
|
+
type ResumeToken
|
|
8
|
+
} from '../change_stream';
|
|
9
|
+
import { type CursorResponse } from '../cmap/wire_protocol/responses';
|
|
10
|
+
import { INIT, RESPONSE } from '../constants';
|
|
11
|
+
import type { MongoClient } from '../mongo_client';
|
|
12
|
+
import { AggregateOperation } from '../operations/aggregate';
|
|
13
|
+
import type { CollationOptions } from '../operations/command';
|
|
14
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
15
|
+
import type { ClientSession } from '../sessions';
|
|
16
|
+
import { maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
17
|
+
import {
|
|
18
|
+
AbstractCursor,
|
|
19
|
+
type AbstractCursorOptions,
|
|
20
|
+
type InitialCursorResponse
|
|
21
|
+
} from './abstract_cursor';
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
export interface ChangeStreamCursorOptions extends AbstractCursorOptions {
|
|
25
|
+
startAtOperationTime?: OperationTime;
|
|
26
|
+
resumeAfter?: ResumeToken;
|
|
27
|
+
startAfter?: ResumeToken;
|
|
28
|
+
maxAwaitTimeMS?: number;
|
|
29
|
+
collation?: CollationOptions;
|
|
30
|
+
fullDocument?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @internal */
|
|
34
|
+
export class ChangeStreamCursor<
|
|
35
|
+
TSchema extends Document = Document,
|
|
36
|
+
TChange extends Document = ChangeStreamDocument<TSchema>
|
|
37
|
+
> extends AbstractCursor<TChange, ChangeStreamEvents> {
|
|
38
|
+
private _resumeToken: ResumeToken;
|
|
39
|
+
private startAtOperationTime: OperationTime | null;
|
|
40
|
+
private hasReceived?: boolean;
|
|
41
|
+
private readonly changeStreamCursorOptions: ChangeStreamCursorOptions;
|
|
42
|
+
private postBatchResumeToken?: ResumeToken;
|
|
43
|
+
private readonly pipeline: Document[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*
|
|
48
|
+
* used to determine change stream resumability
|
|
49
|
+
*/
|
|
50
|
+
maxWireVersion: number | undefined;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
client: MongoClient,
|
|
54
|
+
namespace: MongoDBNamespace,
|
|
55
|
+
pipeline: Document[] = [],
|
|
56
|
+
options: ChangeStreamCursorOptions = {}
|
|
57
|
+
) {
|
|
58
|
+
super(client, namespace, { ...options, tailable: true, awaitData: true });
|
|
59
|
+
|
|
60
|
+
this.pipeline = pipeline;
|
|
61
|
+
this.changeStreamCursorOptions = options;
|
|
62
|
+
this._resumeToken = null;
|
|
63
|
+
this.startAtOperationTime = options.startAtOperationTime ?? null;
|
|
64
|
+
|
|
65
|
+
if (options.startAfter) {
|
|
66
|
+
this.resumeToken = options.startAfter;
|
|
67
|
+
} else if (options.resumeAfter) {
|
|
68
|
+
this.resumeToken = options.resumeAfter;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
set resumeToken(token: ResumeToken) {
|
|
73
|
+
this._resumeToken = token;
|
|
74
|
+
this.emit(ChangeStream.RESUME_TOKEN_CHANGED, token);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get resumeToken(): ResumeToken {
|
|
78
|
+
return this._resumeToken;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get resumeOptions(): ChangeStreamCursorOptions {
|
|
82
|
+
const options: ChangeStreamCursorOptions = {
|
|
83
|
+
...this.changeStreamCursorOptions
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime'] as const) {
|
|
87
|
+
delete options[key];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this.resumeToken != null) {
|
|
91
|
+
if (this.changeStreamCursorOptions.startAfter && !this.hasReceived) {
|
|
92
|
+
options.startAfter = this.resumeToken;
|
|
93
|
+
} else {
|
|
94
|
+
options.resumeAfter = this.resumeToken;
|
|
95
|
+
}
|
|
96
|
+
} else if (this.startAtOperationTime != null) {
|
|
97
|
+
options.startAtOperationTime = this.startAtOperationTime;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return options;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
cacheResumeToken(resumeToken: ResumeToken): void {
|
|
104
|
+
if (this.bufferedCount() === 0 && this.postBatchResumeToken) {
|
|
105
|
+
this.resumeToken = this.postBatchResumeToken;
|
|
106
|
+
} else {
|
|
107
|
+
this.resumeToken = resumeToken;
|
|
108
|
+
}
|
|
109
|
+
this.hasReceived = true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_processBatch(response: CursorResponse): void {
|
|
113
|
+
const { postBatchResumeToken } = response;
|
|
114
|
+
if (postBatchResumeToken) {
|
|
115
|
+
this.postBatchResumeToken = postBatchResumeToken;
|
|
116
|
+
|
|
117
|
+
if (response.batchSize === 0) {
|
|
118
|
+
this.resumeToken = postBatchResumeToken;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
clone(): AbstractCursor<TChange> {
|
|
124
|
+
return new ChangeStreamCursor(this.client, this.namespace, this.pipeline, {
|
|
125
|
+
...this.cursorOptions
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
130
|
+
const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, {
|
|
131
|
+
...this.cursorOptions,
|
|
132
|
+
...this.changeStreamCursorOptions,
|
|
133
|
+
session
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const response = await executeOperation(
|
|
137
|
+
session.client,
|
|
138
|
+
aggregateOperation,
|
|
139
|
+
this.timeoutContext
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const server = aggregateOperation.server;
|
|
143
|
+
this.maxWireVersion = maxWireVersion(server);
|
|
144
|
+
|
|
145
|
+
if (
|
|
146
|
+
this.startAtOperationTime == null &&
|
|
147
|
+
this.changeStreamCursorOptions.resumeAfter == null &&
|
|
148
|
+
this.changeStreamCursorOptions.startAfter == null
|
|
149
|
+
) {
|
|
150
|
+
this.startAtOperationTime = response.operationTime;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this._processBatch(response);
|
|
154
|
+
|
|
155
|
+
this.emit(INIT, response);
|
|
156
|
+
this.emit(RESPONSE);
|
|
157
|
+
|
|
158
|
+
return { server, session, response };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
override async getMore(): Promise<CursorResponse> {
|
|
162
|
+
const response = await super.getMore();
|
|
163
|
+
|
|
164
|
+
this.maxWireVersion = maxWireVersion(this.server);
|
|
165
|
+
this._processBatch(response);
|
|
166
|
+
|
|
167
|
+
this.emit(ChangeStream.MORE, response);
|
|
168
|
+
this.emit(ChangeStream.RESPONSE);
|
|
169
|
+
return response;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type Document } from '../bson';
|
|
2
|
+
import { type ClientBulkWriteCursorResponse } from '../cmap/wire_protocol/responses';
|
|
3
|
+
import type { MongoClient } from '../mongo_client';
|
|
4
|
+
import { ClientBulkWriteOperation } from '../operations/client_bulk_write/client_bulk_write';
|
|
5
|
+
import { type ClientBulkWriteCommandBuilder } from '../operations/client_bulk_write/command_builder';
|
|
6
|
+
import { type ClientBulkWriteOptions } from '../operations/client_bulk_write/common';
|
|
7
|
+
import { executeOperation } from '../operations/execute_operation';
|
|
8
|
+
import type { ClientSession } from '../sessions';
|
|
9
|
+
import { mergeOptions, MongoDBNamespace } from '../utils';
|
|
10
|
+
import {
|
|
11
|
+
AbstractCursor,
|
|
12
|
+
type AbstractCursorOptions,
|
|
13
|
+
type InitialCursorResponse
|
|
14
|
+
} from './abstract_cursor';
|
|
15
|
+
|
|
16
|
+
/** @public */
|
|
17
|
+
export interface ClientBulkWriteCursorOptions
|
|
18
|
+
extends Omit<AbstractCursorOptions, 'maxAwaitTimeMS' | 'tailable' | 'awaitData'>,
|
|
19
|
+
ClientBulkWriteOptions {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This is the cursor that handles client bulk write operations. Note this is never
|
|
23
|
+
* exposed directly to the user and is always immediately exhausted.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export class ClientBulkWriteCursor extends AbstractCursor {
|
|
27
|
+
commandBuilder: ClientBulkWriteCommandBuilder;
|
|
28
|
+
/** @internal */
|
|
29
|
+
private cursorResponse?: ClientBulkWriteCursorResponse;
|
|
30
|
+
/** @internal */
|
|
31
|
+
private clientBulkWriteOptions: ClientBulkWriteOptions;
|
|
32
|
+
|
|
33
|
+
/** @internal */
|
|
34
|
+
constructor(
|
|
35
|
+
client: MongoClient,
|
|
36
|
+
commandBuilder: ClientBulkWriteCommandBuilder,
|
|
37
|
+
options: ClientBulkWriteCursorOptions = {}
|
|
38
|
+
) {
|
|
39
|
+
super(client, new MongoDBNamespace('admin', '$cmd'), options);
|
|
40
|
+
|
|
41
|
+
this.commandBuilder = commandBuilder;
|
|
42
|
+
this.clientBulkWriteOptions = options;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* We need a way to get the top level cursor response fields for
|
|
47
|
+
* generating the bulk write result, so we expose this here.
|
|
48
|
+
*/
|
|
49
|
+
get response(): ClientBulkWriteCursorResponse | null {
|
|
50
|
+
if (this.cursorResponse) return this.cursorResponse;
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get operations(): Document[] {
|
|
55
|
+
return this.commandBuilder.lastOperations;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
clone(): ClientBulkWriteCursor {
|
|
59
|
+
const clonedOptions = mergeOptions({}, this.clientBulkWriteOptions);
|
|
60
|
+
delete clonedOptions.session;
|
|
61
|
+
return new ClientBulkWriteCursor(this.client, this.commandBuilder, {
|
|
62
|
+
...clonedOptions
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @internal */
|
|
67
|
+
async _initialize(session: ClientSession): Promise<InitialCursorResponse> {
|
|
68
|
+
const clientBulkWriteOperation = new ClientBulkWriteOperation(this.commandBuilder, {
|
|
69
|
+
...this.clientBulkWriteOptions,
|
|
70
|
+
...this.cursorOptions,
|
|
71
|
+
session
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const response = await executeOperation(
|
|
75
|
+
this.client,
|
|
76
|
+
clientBulkWriteOperation,
|
|
77
|
+
this.timeoutContext
|
|
78
|
+
);
|
|
79
|
+
this.cursorResponse = response;
|
|
80
|
+
|
|
81
|
+
return { server: clientBulkWriteOperation.server, session, response };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Document } from '../bson';
|
|
2
|
+
import { type ExplainCommandOptions, type ExplainVerbosityLike } from '../explain';
|
|
3
|
+
import { AbstractCursor } from './abstract_cursor';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*
|
|
8
|
+
* A base class for any cursors that have `explain()` methods.
|
|
9
|
+
*/
|
|
10
|
+
export abstract class ExplainableCursor<TSchema> extends AbstractCursor<TSchema> {
|
|
11
|
+
/** Execute the explain for the cursor */
|
|
12
|
+
abstract explain(): Promise<Document>;
|
|
13
|
+
abstract explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
|
|
14
|
+
abstract explain(options: { timeoutMS?: number }): Promise<Document>;
|
|
15
|
+
abstract explain(
|
|
16
|
+
verbosity: ExplainVerbosityLike | ExplainCommandOptions,
|
|
17
|
+
options: { timeoutMS?: number }
|
|
18
|
+
): Promise<Document>;
|
|
19
|
+
abstract explain(
|
|
20
|
+
verbosity?: ExplainVerbosityLike | ExplainCommandOptions | { timeoutMS?: number },
|
|
21
|
+
options?: { timeoutMS?: number }
|
|
22
|
+
): Promise<Document>;
|
|
23
|
+
|
|
24
|
+
protected resolveExplainTimeoutOptions(
|
|
25
|
+
verbosity?: ExplainVerbosityLike | ExplainCommandOptions | { timeoutMS?: number },
|
|
26
|
+
options?: { timeoutMS?: number }
|
|
27
|
+
): { timeout?: { timeoutMS?: number }; explain?: ExplainVerbosityLike | ExplainCommandOptions } {
|
|
28
|
+
let explain: ExplainVerbosityLike | ExplainCommandOptions | undefined;
|
|
29
|
+
let timeout: { timeoutMS?: number } | undefined;
|
|
30
|
+
|
|
31
|
+
if (verbosity == null && options == null) {
|
|
32
|
+
explain = undefined;
|
|
33
|
+
timeout = undefined;
|
|
34
|
+
} else if (verbosity != null && options == null) {
|
|
35
|
+
explain =
|
|
36
|
+
typeof verbosity !== 'object'
|
|
37
|
+
? verbosity
|
|
38
|
+
: 'verbosity' in verbosity
|
|
39
|
+
? verbosity
|
|
40
|
+
: undefined;
|
|
41
|
+
|
|
42
|
+
timeout = typeof verbosity === 'object' && 'timeoutMS' in verbosity ? verbosity : undefined;
|
|
43
|
+
} else {
|
|
44
|
+
// @ts-expect-error TS isn't smart enough to determine that if both options are provided, the first is explain options
|
|
45
|
+
explain = verbosity;
|
|
46
|
+
timeout = options;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { timeout, explain };
|
|
50
|
+
}
|
|
51
|
+
}
|