@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,254 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
|
|
3
|
+
import { type AbstractCursorOptions, type CursorTimeoutMode } from '../cursor/abstract_cursor';
|
|
4
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
5
|
+
import { type ExplainOptions } from '../explain';
|
|
6
|
+
import type { ServerCommandOptions } from '../sdam/server';
|
|
7
|
+
import { formatSort, type Sort } from '../sort';
|
|
8
|
+
import { type TimeoutContext } from '../timeout';
|
|
9
|
+
import { type MongoDBNamespace, normalizeHintField } from '../utils';
|
|
10
|
+
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
|
|
11
|
+
import { Aspect, defineAspects, type Hint } from './operation';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export interface FindOptions
|
|
17
|
+
extends Omit<CommandOperationOptions, 'writeConcern' | 'explain'>,
|
|
18
|
+
AbstractCursorOptions {
|
|
19
|
+
/** Sets the limit of documents returned in the query. */
|
|
20
|
+
limit?: number;
|
|
21
|
+
/** Set to sort the documents coming back from the query. Array of indexes, `[['a', 1]]` etc. */
|
|
22
|
+
sort?: Sort;
|
|
23
|
+
/** The fields to return in the query. Object of fields to either include or exclude (one of, not both), `{'a':1, 'b': 1}` **or** `{'a': 0, 'b': 0}` */
|
|
24
|
+
projection?: Document;
|
|
25
|
+
/** Set to skip N documents ahead in your query (useful for pagination). */
|
|
26
|
+
skip?: number;
|
|
27
|
+
/** Tell the query to use specific indexes in the query. Object of indexes to use, `{'_id':1}` */
|
|
28
|
+
hint?: Hint;
|
|
29
|
+
/** Specify if the cursor can timeout. */
|
|
30
|
+
timeout?: boolean;
|
|
31
|
+
/** Specify if the cursor is tailable. */
|
|
32
|
+
tailable?: boolean;
|
|
33
|
+
/** Specify if the cursor is a tailable-await cursor. Requires `tailable` to be true */
|
|
34
|
+
awaitData?: boolean;
|
|
35
|
+
/** Set the batchSize for the getMoreCommand when iterating over the query results. */
|
|
36
|
+
batchSize?: number;
|
|
37
|
+
/** If true, returns only the index keys in the resulting documents. */
|
|
38
|
+
returnKey?: boolean;
|
|
39
|
+
/** The inclusive lower bound for a specific index */
|
|
40
|
+
min?: Document;
|
|
41
|
+
/** The exclusive upper bound for a specific index */
|
|
42
|
+
max?: Document;
|
|
43
|
+
/** Number of milliseconds to wait before aborting the query. */
|
|
44
|
+
maxTimeMS?: number;
|
|
45
|
+
/** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true */
|
|
46
|
+
maxAwaitTimeMS?: number;
|
|
47
|
+
/** The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that. */
|
|
48
|
+
noCursorTimeout?: boolean;
|
|
49
|
+
/** Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields). */
|
|
50
|
+
collation?: CollationOptions;
|
|
51
|
+
/** Allows disk use for blocking sort operations exceeding 100MB memory. (MongoDB 3.2 or higher) */
|
|
52
|
+
allowDiskUse?: boolean;
|
|
53
|
+
/** Determines whether to close the cursor after the first batch. Defaults to false. */
|
|
54
|
+
singleBatch?: boolean;
|
|
55
|
+
/** For queries against a sharded collection, allows the command (or subsequent getMore commands) to return partial results, rather than an error, if one or more queried shards are unavailable. */
|
|
56
|
+
allowPartialResults?: boolean;
|
|
57
|
+
/** Determines whether to return the record identifier for each document. If true, adds a field $recordId to the returned documents. */
|
|
58
|
+
showRecordId?: boolean;
|
|
59
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
60
|
+
let?: Document;
|
|
61
|
+
/**
|
|
62
|
+
* Option to enable an optimized code path for queries looking for a particular range of `ts` values in the oplog. Requires `tailable` to be true.
|
|
63
|
+
* @deprecated Starting from MongoDB 4.4 this flag is not needed and will be ignored.
|
|
64
|
+
*/
|
|
65
|
+
oplogReplay?: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Specifies the verbosity mode for the explain output.
|
|
69
|
+
* @deprecated This API is deprecated in favor of `collection.find().explain()`.
|
|
70
|
+
*/
|
|
71
|
+
explain?: ExplainOptions['explain'];
|
|
72
|
+
/** @internal*/
|
|
73
|
+
timeoutMode?: CursorTimeoutMode;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @public */
|
|
77
|
+
export type FindOneOptions = Omit<FindOptions, 'batchSize' | 'limit' | 'noCursorTimeout'>;
|
|
78
|
+
|
|
79
|
+
/** @internal */
|
|
80
|
+
export class FindOperation extends CommandOperation<CursorResponse> {
|
|
81
|
+
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @remarks WriteConcern can still be present on the options because
|
|
85
|
+
* we inherit options from the client/db/collection. The
|
|
86
|
+
* key must be present on the options in order to delete it.
|
|
87
|
+
* This allows typescript to delete the key but will
|
|
88
|
+
* not allow a writeConcern to be assigned as a property on options.
|
|
89
|
+
*/
|
|
90
|
+
override options: FindOptions & { writeConcern?: never };
|
|
91
|
+
filter: Document;
|
|
92
|
+
|
|
93
|
+
constructor(ns: MongoDBNamespace, filter: Document = {}, options: FindOptions = {}) {
|
|
94
|
+
super(undefined, options);
|
|
95
|
+
|
|
96
|
+
this.options = { ...options };
|
|
97
|
+
delete this.options.writeConcern;
|
|
98
|
+
this.ns = ns;
|
|
99
|
+
|
|
100
|
+
if (typeof filter !== 'object' || Array.isArray(filter)) {
|
|
101
|
+
throw new MongoInvalidArgumentError('Query filter must be a plain object or ObjectId');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// special case passing in an ObjectId as a filter
|
|
105
|
+
this.filter = filter != null && filter._bsontype === 'ObjectId' ? { _id: filter } : filter;
|
|
106
|
+
|
|
107
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = this.explain ? ExplainedCursorResponse : CursorResponse;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
override get commandName() {
|
|
111
|
+
return 'find' as const;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
115
|
+
return {
|
|
116
|
+
...this.options,
|
|
117
|
+
...this.bsonOptions,
|
|
118
|
+
documentsReturnedIn: 'firstBatch',
|
|
119
|
+
session: this.session,
|
|
120
|
+
timeoutContext
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
override handleOk(
|
|
125
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
126
|
+
): CursorResponse {
|
|
127
|
+
return response;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override buildCommandDocument(): Document {
|
|
131
|
+
return makeFindCommand(this.ns, this.filter, this.options);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOptions): Document {
|
|
136
|
+
const findCommand: Document = {
|
|
137
|
+
find: ns.collection,
|
|
138
|
+
filter
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if (options.sort) {
|
|
142
|
+
findCommand.sort = formatSort(options.sort);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (options.projection) {
|
|
146
|
+
let projection = options.projection;
|
|
147
|
+
if (projection && Array.isArray(projection)) {
|
|
148
|
+
projection = projection.length
|
|
149
|
+
? projection.reduce((result, field) => {
|
|
150
|
+
result[field] = 1;
|
|
151
|
+
return result;
|
|
152
|
+
}, {})
|
|
153
|
+
: { _id: 1 };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
findCommand.projection = projection;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (options.hint) {
|
|
160
|
+
findCommand.hint = normalizeHintField(options.hint);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (typeof options.skip === 'number') {
|
|
164
|
+
findCommand.skip = options.skip;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (typeof options.limit === 'number') {
|
|
168
|
+
if (options.limit < 0) {
|
|
169
|
+
findCommand.limit = -options.limit;
|
|
170
|
+
findCommand.singleBatch = true;
|
|
171
|
+
} else {
|
|
172
|
+
findCommand.limit = options.limit;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (typeof options.batchSize === 'number') {
|
|
177
|
+
if (options.batchSize < 0) {
|
|
178
|
+
findCommand.limit = -options.batchSize;
|
|
179
|
+
} else {
|
|
180
|
+
if (options.batchSize === options.limit) {
|
|
181
|
+
// Spec dictates that if these are equal the batchSize should be one more than the
|
|
182
|
+
// limit to avoid leaving the cursor open.
|
|
183
|
+
findCommand.batchSize = options.batchSize + 1;
|
|
184
|
+
} else {
|
|
185
|
+
findCommand.batchSize = options.batchSize;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (typeof options.singleBatch === 'boolean') {
|
|
191
|
+
findCommand.singleBatch = options.singleBatch;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// we check for undefined specifically here to allow falsy values
|
|
195
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
196
|
+
if (options.comment !== undefined) {
|
|
197
|
+
findCommand.comment = options.comment;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (options.max) {
|
|
201
|
+
findCommand.max = options.max;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (options.min) {
|
|
205
|
+
findCommand.min = options.min;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (typeof options.returnKey === 'boolean') {
|
|
209
|
+
findCommand.returnKey = options.returnKey;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (typeof options.showRecordId === 'boolean') {
|
|
213
|
+
findCommand.showRecordId = options.showRecordId;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (typeof options.tailable === 'boolean') {
|
|
217
|
+
findCommand.tailable = options.tailable;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (typeof options.oplogReplay === 'boolean') {
|
|
221
|
+
findCommand.oplogReplay = options.oplogReplay;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (typeof options.timeout === 'boolean') {
|
|
225
|
+
findCommand.noCursorTimeout = !options.timeout;
|
|
226
|
+
} else if (typeof options.noCursorTimeout === 'boolean') {
|
|
227
|
+
findCommand.noCursorTimeout = options.noCursorTimeout;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (typeof options.awaitData === 'boolean') {
|
|
231
|
+
findCommand.awaitData = options.awaitData;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (typeof options.allowPartialResults === 'boolean') {
|
|
235
|
+
findCommand.allowPartialResults = options.allowPartialResults;
|
|
236
|
+
}
|
|
237
|
+
if (typeof options.allowDiskUse === 'boolean') {
|
|
238
|
+
findCommand.allowDiskUse = options.allowDiskUse;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (options.let) {
|
|
242
|
+
findCommand.let = options.let;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return findCommand;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
defineAspects(FindOperation, [
|
|
249
|
+
Aspect.READ_OPERATION,
|
|
250
|
+
Aspect.RETRYABLE,
|
|
251
|
+
Aspect.EXPLAINABLE,
|
|
252
|
+
Aspect.CURSOR_CREATING,
|
|
253
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
254
|
+
]);
|
|
@@ -0,0 +1,319 @@
|
|
|
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 { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
|
|
6
|
+
import { ReadPreference } from '../read_preference';
|
|
7
|
+
import type { ClientSession } from '../sessions';
|
|
8
|
+
import { formatSort, type Sort, type SortForCmd } from '../sort';
|
|
9
|
+
import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
|
|
10
|
+
import { type WriteConcern, type WriteConcernSettings } from '../write_concern';
|
|
11
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
12
|
+
import { Aspect, defineAspects } from './operation';
|
|
13
|
+
|
|
14
|
+
/** @public */
|
|
15
|
+
export const ReturnDocument = Object.freeze({
|
|
16
|
+
BEFORE: 'before',
|
|
17
|
+
AFTER: 'after'
|
|
18
|
+
} as const);
|
|
19
|
+
|
|
20
|
+
/** @public */
|
|
21
|
+
export type ReturnDocument = (typeof ReturnDocument)[keyof typeof ReturnDocument];
|
|
22
|
+
|
|
23
|
+
/** @public */
|
|
24
|
+
export interface FindOneAndDeleteOptions extends CommandOperationOptions {
|
|
25
|
+
/** An optional hint for query optimization. See the {@link https://www.mongodb.com/docs/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
|
|
26
|
+
hint?: Document;
|
|
27
|
+
/** Limits the fields to return for all matching documents. */
|
|
28
|
+
projection?: Document;
|
|
29
|
+
/** Determines which document the operation modifies if the query selects multiple documents. */
|
|
30
|
+
sort?: Sort;
|
|
31
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
32
|
+
let?: Document;
|
|
33
|
+
/**
|
|
34
|
+
* Return the ModifyResult instead of the modified document. Defaults to false
|
|
35
|
+
*/
|
|
36
|
+
includeResultMetadata?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @public */
|
|
40
|
+
export interface FindOneAndReplaceOptions extends CommandOperationOptions {
|
|
41
|
+
/** Allow driver to bypass schema validation. */
|
|
42
|
+
bypassDocumentValidation?: boolean;
|
|
43
|
+
/** An optional hint for query optimization. See the {@link https://www.mongodb.com/docs/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
|
|
44
|
+
hint?: Document;
|
|
45
|
+
/** Limits the fields to return for all matching documents. */
|
|
46
|
+
projection?: Document;
|
|
47
|
+
/** When set to 'after', returns the updated document rather than the original. The default is 'before'. */
|
|
48
|
+
returnDocument?: ReturnDocument;
|
|
49
|
+
/** Determines which document the operation modifies if the query selects multiple documents. */
|
|
50
|
+
sort?: Sort;
|
|
51
|
+
/** Upsert the document if it does not exist. */
|
|
52
|
+
upsert?: boolean;
|
|
53
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
54
|
+
let?: Document;
|
|
55
|
+
/**
|
|
56
|
+
* Return the ModifyResult instead of the modified document. Defaults to false
|
|
57
|
+
*/
|
|
58
|
+
includeResultMetadata?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @public */
|
|
62
|
+
export interface FindOneAndUpdateOptions extends CommandOperationOptions {
|
|
63
|
+
/** Optional list of array filters referenced in filtered positional operators */
|
|
64
|
+
arrayFilters?: Document[];
|
|
65
|
+
/** Allow driver to bypass schema validation. */
|
|
66
|
+
bypassDocumentValidation?: boolean;
|
|
67
|
+
/** An optional hint for query optimization. See the {@link https://www.mongodb.com/docs/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
|
|
68
|
+
hint?: Document;
|
|
69
|
+
/** Limits the fields to return for all matching documents. */
|
|
70
|
+
projection?: Document;
|
|
71
|
+
/** When set to 'after', returns the updated document rather than the original. The default is 'before'. */
|
|
72
|
+
returnDocument?: ReturnDocument;
|
|
73
|
+
/** Determines which document the operation modifies if the query selects multiple documents. */
|
|
74
|
+
sort?: Sort;
|
|
75
|
+
/** Upsert the document if it does not exist. */
|
|
76
|
+
upsert?: boolean;
|
|
77
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
78
|
+
let?: Document;
|
|
79
|
+
/**
|
|
80
|
+
* Return the ModifyResult instead of the modified document. Defaults to false
|
|
81
|
+
*/
|
|
82
|
+
includeResultMetadata?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @internal */
|
|
86
|
+
interface FindAndModifyCmdBase {
|
|
87
|
+
remove: boolean;
|
|
88
|
+
new: boolean;
|
|
89
|
+
upsert: boolean;
|
|
90
|
+
update?: Document;
|
|
91
|
+
sort?: SortForCmd;
|
|
92
|
+
fields?: Document;
|
|
93
|
+
bypassDocumentValidation?: boolean;
|
|
94
|
+
arrayFilters?: Document[];
|
|
95
|
+
maxTimeMS?: number;
|
|
96
|
+
let?: Document;
|
|
97
|
+
writeConcern?: WriteConcern | WriteConcernSettings;
|
|
98
|
+
/**
|
|
99
|
+
* Comment to apply to the operation.
|
|
100
|
+
*
|
|
101
|
+
* In server versions pre-4.4, 'comment' must be string. A server
|
|
102
|
+
* error will be thrown if any other type is provided.
|
|
103
|
+
*
|
|
104
|
+
* In server versions 4.4 and above, 'comment' can be any valid BSON type.
|
|
105
|
+
*/
|
|
106
|
+
comment?: unknown;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function configureFindAndModifyCmdBaseUpdateOpts(
|
|
110
|
+
cmdBase: FindAndModifyCmdBase,
|
|
111
|
+
options: FindOneAndReplaceOptions | FindOneAndUpdateOptions
|
|
112
|
+
): FindAndModifyCmdBase {
|
|
113
|
+
cmdBase.new = options.returnDocument === ReturnDocument.AFTER;
|
|
114
|
+
cmdBase.upsert = options.upsert === true;
|
|
115
|
+
|
|
116
|
+
if (options.bypassDocumentValidation === true) {
|
|
117
|
+
cmdBase.bypassDocumentValidation = options.bypassDocumentValidation;
|
|
118
|
+
}
|
|
119
|
+
return cmdBase;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** @internal */
|
|
123
|
+
export class FindAndModifyOperation extends CommandOperation<Document> {
|
|
124
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
125
|
+
override options: FindOneAndReplaceOptions | FindOneAndUpdateOptions | FindOneAndDeleteOptions;
|
|
126
|
+
collection: Collection;
|
|
127
|
+
query: Document;
|
|
128
|
+
doc?: Document;
|
|
129
|
+
|
|
130
|
+
constructor(
|
|
131
|
+
collection: Collection,
|
|
132
|
+
query: Document,
|
|
133
|
+
options: FindOneAndReplaceOptions | FindOneAndUpdateOptions | FindOneAndDeleteOptions
|
|
134
|
+
) {
|
|
135
|
+
super(collection, options);
|
|
136
|
+
this.options = options;
|
|
137
|
+
// force primary read preference
|
|
138
|
+
this.readPreference = ReadPreference.primary;
|
|
139
|
+
|
|
140
|
+
this.collection = collection;
|
|
141
|
+
this.query = query;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
override get commandName() {
|
|
145
|
+
return 'findAndModify' as const;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
override buildCommandDocument(
|
|
149
|
+
connection: Connection,
|
|
150
|
+
_session?: ClientSession
|
|
151
|
+
): Document & FindAndModifyCmdBase {
|
|
152
|
+
const options = this.options;
|
|
153
|
+
const command: Document & FindAndModifyCmdBase = {
|
|
154
|
+
findAndModify: this.collection.collectionName,
|
|
155
|
+
query: this.query,
|
|
156
|
+
remove: false,
|
|
157
|
+
new: false,
|
|
158
|
+
upsert: false
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
options.includeResultMetadata ??= false;
|
|
162
|
+
|
|
163
|
+
const sort = formatSort(options.sort);
|
|
164
|
+
if (sort) {
|
|
165
|
+
command.sort = sort;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (options.projection) {
|
|
169
|
+
command.fields = options.projection;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (options.maxTimeMS) {
|
|
173
|
+
command.maxTimeMS = options.maxTimeMS;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Decorate the findAndModify command with the write Concern
|
|
177
|
+
if (options.writeConcern) {
|
|
178
|
+
command.writeConcern = options.writeConcern;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (options.let) {
|
|
182
|
+
command.let = options.let;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// we check for undefined specifically here to allow falsy values
|
|
186
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
187
|
+
if (options.comment !== undefined) {
|
|
188
|
+
command.comment = options.comment;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
decorateWithCollation(command, options);
|
|
192
|
+
|
|
193
|
+
if (options.hint) {
|
|
194
|
+
const unacknowledgedWrite = this.writeConcern?.w === 0;
|
|
195
|
+
if (unacknowledgedWrite && maxWireVersion(connection) < 9) {
|
|
196
|
+
throw new MongoCompatibilityError(
|
|
197
|
+
'hint for the findAndModify command is only supported on MongoDB 4.4+'
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
command.hint = options.hint;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return command;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
|
|
208
|
+
const result = super.handleOk(response);
|
|
209
|
+
return this.options.includeResultMetadata ? result : (result.value ?? null);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** @internal */
|
|
214
|
+
export class FindOneAndDeleteOperation extends FindAndModifyOperation {
|
|
215
|
+
constructor(collection: Collection, filter: Document, options: FindOneAndDeleteOptions) {
|
|
216
|
+
// Basic validation
|
|
217
|
+
if (filter == null || typeof filter !== 'object') {
|
|
218
|
+
throw new MongoInvalidArgumentError('Argument "filter" must be an object');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
super(collection, filter, options);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
override buildCommandDocument(
|
|
225
|
+
connection: Connection,
|
|
226
|
+
session?: ClientSession
|
|
227
|
+
): Document & FindAndModifyCmdBase {
|
|
228
|
+
const document = super.buildCommandDocument(connection, session);
|
|
229
|
+
document.remove = true;
|
|
230
|
+
return document;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** @internal */
|
|
235
|
+
export class FindOneAndReplaceOperation extends FindAndModifyOperation {
|
|
236
|
+
private replacement: Document;
|
|
237
|
+
constructor(
|
|
238
|
+
collection: Collection,
|
|
239
|
+
filter: Document,
|
|
240
|
+
replacement: Document,
|
|
241
|
+
options: FindOneAndReplaceOptions
|
|
242
|
+
) {
|
|
243
|
+
if (filter == null || typeof filter !== 'object') {
|
|
244
|
+
throw new MongoInvalidArgumentError('Argument "filter" must be an object');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (replacement == null || typeof replacement !== 'object') {
|
|
248
|
+
throw new MongoInvalidArgumentError('Argument "replacement" must be an object');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (hasAtomicOperators(replacement)) {
|
|
252
|
+
throw new MongoInvalidArgumentError('Replacement document must not contain atomic operators');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
super(collection, filter, options);
|
|
256
|
+
this.replacement = replacement;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
override buildCommandDocument(
|
|
260
|
+
connection: Connection,
|
|
261
|
+
session?: ClientSession
|
|
262
|
+
): Document & FindAndModifyCmdBase {
|
|
263
|
+
const document = super.buildCommandDocument(connection, session);
|
|
264
|
+
document.update = this.replacement;
|
|
265
|
+
configureFindAndModifyCmdBaseUpdateOpts(document, this.options);
|
|
266
|
+
return document;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** @internal */
|
|
271
|
+
export class FindOneAndUpdateOperation extends FindAndModifyOperation {
|
|
272
|
+
override options: FindOneAndUpdateOptions;
|
|
273
|
+
|
|
274
|
+
private update: Document;
|
|
275
|
+
constructor(
|
|
276
|
+
collection: Collection,
|
|
277
|
+
filter: Document,
|
|
278
|
+
update: Document,
|
|
279
|
+
options: FindOneAndUpdateOptions
|
|
280
|
+
) {
|
|
281
|
+
if (filter == null || typeof filter !== 'object') {
|
|
282
|
+
throw new MongoInvalidArgumentError('Argument "filter" must be an object');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (update == null || typeof update !== 'object') {
|
|
286
|
+
throw new MongoInvalidArgumentError('Argument "update" must be an object');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!hasAtomicOperators(update, options)) {
|
|
290
|
+
throw new MongoInvalidArgumentError('Update document requires atomic operators');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
super(collection, filter, options);
|
|
294
|
+
this.update = update;
|
|
295
|
+
this.options = options;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
override buildCommandDocument(
|
|
299
|
+
connection: Connection,
|
|
300
|
+
session?: ClientSession
|
|
301
|
+
): Document & FindAndModifyCmdBase {
|
|
302
|
+
const document = super.buildCommandDocument(connection, session);
|
|
303
|
+
document.update = this.update;
|
|
304
|
+
configureFindAndModifyCmdBaseUpdateOpts(document, this.options);
|
|
305
|
+
|
|
306
|
+
if (this.options.arrayFilters) {
|
|
307
|
+
document.arrayFilters = this.options.arrayFilters;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return document;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
defineAspects(FindAndModifyOperation, [
|
|
315
|
+
Aspect.WRITE_OPERATION,
|
|
316
|
+
Aspect.RETRYABLE,
|
|
317
|
+
Aspect.EXPLAINABLE,
|
|
318
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
319
|
+
]);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Document, Long } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { CursorResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import { MongoRuntimeError } from '../error';
|
|
5
|
+
import type { Server, ServerCommandOptions } from '../sdam/server';
|
|
6
|
+
import { type TimeoutContext } from '../timeout';
|
|
7
|
+
import { maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
8
|
+
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
export interface GetMoreOptions extends OperationOptions {
|
|
12
|
+
/** Set the batchSize for the getMoreCommand when iterating over the query results. */
|
|
13
|
+
batchSize?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Comment to apply to the operation.
|
|
16
|
+
*
|
|
17
|
+
* getMore only supports 'comment' in server versions 4.4 and above.
|
|
18
|
+
*/
|
|
19
|
+
comment?: unknown;
|
|
20
|
+
/** Number of milliseconds to wait before aborting the query. */
|
|
21
|
+
maxTimeMS?: number;
|
|
22
|
+
/** TODO(NODE-4413): Address bug with maxAwaitTimeMS not being passed in from the cursor correctly */
|
|
23
|
+
maxAwaitTimeMS?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* GetMore command: https://www.mongodb.com/docs/manual/reference/command/getMore/
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export interface GetMoreCommand {
|
|
31
|
+
getMore: Long;
|
|
32
|
+
collection: string;
|
|
33
|
+
batchSize?: number;
|
|
34
|
+
maxTimeMS?: number;
|
|
35
|
+
/** Only supported on wire versions 10 or greater */
|
|
36
|
+
comment?: unknown;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @internal */
|
|
40
|
+
export class GetMoreOperation extends AbstractOperation<CursorResponse> {
|
|
41
|
+
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
42
|
+
cursorId: Long;
|
|
43
|
+
override options: GetMoreOptions;
|
|
44
|
+
|
|
45
|
+
constructor(ns: MongoDBNamespace, cursorId: Long, server: Server, options: GetMoreOptions) {
|
|
46
|
+
super(options);
|
|
47
|
+
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.ns = ns;
|
|
50
|
+
this.cursorId = cursorId;
|
|
51
|
+
this.server = server;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
override get commandName() {
|
|
55
|
+
return 'getMore' as const;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override buildCommand(connection: Connection): Document {
|
|
59
|
+
if (this.cursorId == null || this.cursorId.isZero()) {
|
|
60
|
+
throw new MongoRuntimeError('Unable to iterate cursor with no id');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const collection = this.ns.collection;
|
|
64
|
+
if (collection == null) {
|
|
65
|
+
// Cursors should have adopted the namespace returned by MongoDB
|
|
66
|
+
// which should always defined a collection name (even a pseudo one, ex. db.aggregate())
|
|
67
|
+
throw new MongoRuntimeError('A collection name must be determined before getMore');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const getMoreCmd: GetMoreCommand = {
|
|
71
|
+
getMore: this.cursorId,
|
|
72
|
+
collection
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (typeof this.options.batchSize === 'number') {
|
|
76
|
+
getMoreCmd.batchSize = Math.abs(this.options.batchSize);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof this.options.maxAwaitTimeMS === 'number') {
|
|
80
|
+
getMoreCmd.maxTimeMS = this.options.maxAwaitTimeMS;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// we check for undefined specifically here to allow falsy values
|
|
84
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
85
|
+
if (this.options.comment !== undefined && maxWireVersion(connection) >= 9) {
|
|
86
|
+
getMoreCmd.comment = this.options.comment;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return getMoreCmd;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
93
|
+
return {
|
|
94
|
+
returnFieldSelector: null,
|
|
95
|
+
documentsReturnedIn: 'nextBatch',
|
|
96
|
+
timeoutContext,
|
|
97
|
+
...this.options
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
override handleOk(
|
|
102
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
103
|
+
): CursorResponse {
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
defineAspects(GetMoreOperation, [Aspect.READ_OPERATION, Aspect.MUST_SELECT_SAME_SERVER]);
|