@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,418 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { CursorResponse, MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import type { Collection } from '../collection';
|
|
5
|
+
import { type AbstractCursorOptions } from '../cursor/abstract_cursor';
|
|
6
|
+
import { MongoCompatibilityError } from '../error';
|
|
7
|
+
import { type OneOrMore } from '../mongo_types';
|
|
8
|
+
import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
9
|
+
import {
|
|
10
|
+
type CollationOptions,
|
|
11
|
+
CommandOperation,
|
|
12
|
+
type CommandOperationOptions,
|
|
13
|
+
type OperationParent
|
|
14
|
+
} from './command';
|
|
15
|
+
import { Aspect, defineAspects } from './operation';
|
|
16
|
+
|
|
17
|
+
const VALID_INDEX_OPTIONS = new Set([
|
|
18
|
+
'background',
|
|
19
|
+
'unique',
|
|
20
|
+
'name',
|
|
21
|
+
'partialFilterExpression',
|
|
22
|
+
'sparse',
|
|
23
|
+
'hidden',
|
|
24
|
+
'expireAfterSeconds',
|
|
25
|
+
'storageEngine',
|
|
26
|
+
'collation',
|
|
27
|
+
'version',
|
|
28
|
+
|
|
29
|
+
// text indexes
|
|
30
|
+
'weights',
|
|
31
|
+
'default_language',
|
|
32
|
+
'language_override',
|
|
33
|
+
'textIndexVersion',
|
|
34
|
+
|
|
35
|
+
// 2d-sphere indexes
|
|
36
|
+
'2dsphereIndexVersion',
|
|
37
|
+
|
|
38
|
+
// 2d indexes
|
|
39
|
+
'bits',
|
|
40
|
+
'min',
|
|
41
|
+
'max',
|
|
42
|
+
|
|
43
|
+
// geoHaystack Indexes
|
|
44
|
+
'bucketSize',
|
|
45
|
+
|
|
46
|
+
// wildcard indexes
|
|
47
|
+
'wildcardProjection'
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
/** @public */
|
|
51
|
+
export type IndexDirection =
|
|
52
|
+
| -1
|
|
53
|
+
| 1
|
|
54
|
+
| '2d'
|
|
55
|
+
| '2dsphere'
|
|
56
|
+
| 'text'
|
|
57
|
+
| 'geoHaystack'
|
|
58
|
+
| 'hashed'
|
|
59
|
+
| number;
|
|
60
|
+
|
|
61
|
+
function isIndexDirection(x: unknown): x is IndexDirection {
|
|
62
|
+
return (
|
|
63
|
+
typeof x === 'number' || x === '2d' || x === '2dsphere' || x === 'text' || x === 'geoHaystack'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
/** @public */
|
|
67
|
+
export type IndexSpecification = OneOrMore<
|
|
68
|
+
| string
|
|
69
|
+
| [string, IndexDirection]
|
|
70
|
+
| { [key: string]: IndexDirection }
|
|
71
|
+
| Map<string, IndexDirection>
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
/** @public */
|
|
75
|
+
export interface IndexInformationOptions extends ListIndexesOptions {
|
|
76
|
+
/**
|
|
77
|
+
* When `true`, an array of index descriptions is returned.
|
|
78
|
+
* When `false`, the driver returns an object that with keys corresponding to index names with values
|
|
79
|
+
* corresponding to the entries of the indexes' key.
|
|
80
|
+
*
|
|
81
|
+
* For example, the given the following indexes:
|
|
82
|
+
* ```
|
|
83
|
+
* [ { name: 'a_1', key: { a: 1 } }, { name: 'b_1_c_1' , key: { b: 1, c: 1 } }]
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* When `full` is `true`, the above array is returned. When `full` is `false`, the following is returned:
|
|
87
|
+
* ```
|
|
88
|
+
* {
|
|
89
|
+
* 'a_1': [['a', 1]],
|
|
90
|
+
* 'b_1_c_1': [['b', 1], ['c', 1]],
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
full?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @public */
|
|
98
|
+
export interface IndexDescription
|
|
99
|
+
extends Pick<
|
|
100
|
+
CreateIndexesOptions,
|
|
101
|
+
| 'background'
|
|
102
|
+
| 'unique'
|
|
103
|
+
| 'partialFilterExpression'
|
|
104
|
+
| 'sparse'
|
|
105
|
+
| 'hidden'
|
|
106
|
+
| 'expireAfterSeconds'
|
|
107
|
+
| 'storageEngine'
|
|
108
|
+
| 'version'
|
|
109
|
+
| 'weights'
|
|
110
|
+
| 'default_language'
|
|
111
|
+
| 'language_override'
|
|
112
|
+
| 'textIndexVersion'
|
|
113
|
+
| '2dsphereIndexVersion'
|
|
114
|
+
| 'bits'
|
|
115
|
+
| 'min'
|
|
116
|
+
| 'max'
|
|
117
|
+
| 'bucketSize'
|
|
118
|
+
| 'wildcardProjection'
|
|
119
|
+
> {
|
|
120
|
+
collation?: CollationOptions;
|
|
121
|
+
name?: string;
|
|
122
|
+
key: { [key: string]: IndexDirection } | Map<string, IndexDirection>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @public */
|
|
126
|
+
export interface CreateIndexesOptions extends Omit<CommandOperationOptions, 'writeConcern'> {
|
|
127
|
+
/** Creates the index in the background, yielding whenever possible. */
|
|
128
|
+
background?: boolean;
|
|
129
|
+
/** Creates an unique index. */
|
|
130
|
+
unique?: boolean;
|
|
131
|
+
/** Override the autogenerated index name (useful if the resulting name is larger than 128 bytes) */
|
|
132
|
+
name?: string;
|
|
133
|
+
/** Creates a partial index based on the given filter object (MongoDB 3.2 or higher) */
|
|
134
|
+
partialFilterExpression?: Document;
|
|
135
|
+
/** Creates a sparse index. */
|
|
136
|
+
sparse?: boolean;
|
|
137
|
+
/** Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) */
|
|
138
|
+
expireAfterSeconds?: number;
|
|
139
|
+
/** Allows users to configure the storage engine on a per-index basis when creating an index. (MongoDB 3.0 or higher) */
|
|
140
|
+
storageEngine?: Document;
|
|
141
|
+
/** (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes. */
|
|
142
|
+
commitQuorum?: number | string;
|
|
143
|
+
/** Specifies the index version number, either 0 or 1. */
|
|
144
|
+
version?: number;
|
|
145
|
+
// text indexes
|
|
146
|
+
weights?: Document;
|
|
147
|
+
default_language?: string;
|
|
148
|
+
language_override?: string;
|
|
149
|
+
textIndexVersion?: number;
|
|
150
|
+
// 2d-sphere indexes
|
|
151
|
+
'2dsphereIndexVersion'?: number;
|
|
152
|
+
// 2d indexes
|
|
153
|
+
bits?: number;
|
|
154
|
+
/** For geospatial indexes set the lower bound for the co-ordinates. */
|
|
155
|
+
min?: number;
|
|
156
|
+
/** For geospatial indexes set the high bound for the co-ordinates. */
|
|
157
|
+
max?: number;
|
|
158
|
+
// geoHaystack Indexes
|
|
159
|
+
bucketSize?: number;
|
|
160
|
+
// wildcard indexes
|
|
161
|
+
wildcardProjection?: Document;
|
|
162
|
+
/** Specifies that the index should exist on the target collection but should not be used by the query planner when executing operations. (MongoDB 4.4 or higher) */
|
|
163
|
+
hidden?: boolean;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function isSingleIndexTuple(t: unknown): t is [string, IndexDirection] {
|
|
167
|
+
return Array.isArray(t) && t.length === 2 && isIndexDirection(t[1]);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Converts an `IndexSpecification`, which can be specified in multiple formats, into a
|
|
172
|
+
* valid `key` for the createIndexes command.
|
|
173
|
+
*/
|
|
174
|
+
function constructIndexDescriptionMap(indexSpec: IndexSpecification): Map<string, IndexDirection> {
|
|
175
|
+
const key: Map<string, IndexDirection> = new Map();
|
|
176
|
+
|
|
177
|
+
const indexSpecs =
|
|
178
|
+
!Array.isArray(indexSpec) || isSingleIndexTuple(indexSpec) ? [indexSpec] : indexSpec;
|
|
179
|
+
|
|
180
|
+
// Iterate through array and handle different types
|
|
181
|
+
for (const spec of indexSpecs) {
|
|
182
|
+
if (typeof spec === 'string') {
|
|
183
|
+
key.set(spec, 1);
|
|
184
|
+
} else if (Array.isArray(spec)) {
|
|
185
|
+
key.set(spec[0], spec[1] ?? 1);
|
|
186
|
+
} else if (spec instanceof Map) {
|
|
187
|
+
for (const [property, value] of spec) {
|
|
188
|
+
key.set(property, value);
|
|
189
|
+
}
|
|
190
|
+
} else if (isObject(spec)) {
|
|
191
|
+
for (const [property, value] of Object.entries(spec)) {
|
|
192
|
+
key.set(property, value);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return key;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Receives an index description and returns a modified index description which has had invalid options removed
|
|
202
|
+
* from the description and has mapped the `version` option to the `v` option.
|
|
203
|
+
*/
|
|
204
|
+
function resolveIndexDescription(
|
|
205
|
+
description: IndexDescription
|
|
206
|
+
): Omit<ResolvedIndexDescription, 'key'> {
|
|
207
|
+
const validProvidedOptions = Object.entries(description).filter(([optionName]) =>
|
|
208
|
+
VALID_INDEX_OPTIONS.has(optionName)
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
return Object.fromEntries(
|
|
212
|
+
// we support the `version` option, but the `createIndexes` command expects it to be the `v`
|
|
213
|
+
validProvidedOptions.map(([name, value]) => (name === 'version' ? ['v', value] : [name, value]))
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @public
|
|
219
|
+
* The index information returned by the listIndexes command. https://www.mongodb.com/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes
|
|
220
|
+
*/
|
|
221
|
+
export type IndexDescriptionInfo = Omit<IndexDescription, 'key' | 'version'> & {
|
|
222
|
+
key: { [key: string]: IndexDirection };
|
|
223
|
+
v?: IndexDescription['version'];
|
|
224
|
+
} & Document;
|
|
225
|
+
|
|
226
|
+
/** @public */
|
|
227
|
+
export type IndexDescriptionCompact = Record<string, [name: string, direction: IndexDirection][]>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @internal
|
|
231
|
+
*
|
|
232
|
+
* Internally, the driver represents index description keys with `Map`s to preserve key ordering.
|
|
233
|
+
* We don't require users to specify maps, so we transform user provided descriptions into
|
|
234
|
+
* "resolved" by converting the `key` into a JS `Map`, if it isn't already a map.
|
|
235
|
+
*
|
|
236
|
+
* Additionally, we support the `version` option, but the `createIndexes` command uses the field `v`
|
|
237
|
+
* to specify the index version so we map the value of `version` to `v`, if provided.
|
|
238
|
+
*/
|
|
239
|
+
type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
|
|
240
|
+
key: Map<string, IndexDirection>;
|
|
241
|
+
v?: IndexDescription['version'];
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** @internal */
|
|
245
|
+
export class CreateIndexesOperation extends CommandOperation<string[]> {
|
|
246
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
247
|
+
override options: CreateIndexesOptions;
|
|
248
|
+
collectionName: string;
|
|
249
|
+
indexes: ReadonlyArray<ResolvedIndexDescription>;
|
|
250
|
+
|
|
251
|
+
private constructor(
|
|
252
|
+
parent: OperationParent,
|
|
253
|
+
collectionName: string,
|
|
254
|
+
indexes: IndexDescription[],
|
|
255
|
+
options?: CreateIndexesOptions
|
|
256
|
+
) {
|
|
257
|
+
super(parent, options);
|
|
258
|
+
|
|
259
|
+
this.options = options ?? {};
|
|
260
|
+
// collation is set on each index, it should not be defined at the root
|
|
261
|
+
this.options.collation = undefined;
|
|
262
|
+
this.collectionName = collectionName;
|
|
263
|
+
this.indexes = indexes.map((userIndex: IndexDescription): ResolvedIndexDescription => {
|
|
264
|
+
// Ensure the key is a Map to preserve index key ordering
|
|
265
|
+
const key =
|
|
266
|
+
userIndex.key instanceof Map ? userIndex.key : new Map(Object.entries(userIndex.key));
|
|
267
|
+
const name = userIndex.name ?? Array.from(key).flat().join('_');
|
|
268
|
+
const validIndexOptions = resolveIndexDescription(userIndex);
|
|
269
|
+
return {
|
|
270
|
+
...validIndexOptions,
|
|
271
|
+
name,
|
|
272
|
+
key
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
this.ns = parent.s.namespace;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
static fromIndexDescriptionArray(
|
|
279
|
+
parent: OperationParent,
|
|
280
|
+
collectionName: string,
|
|
281
|
+
indexes: IndexDescription[],
|
|
282
|
+
options?: CreateIndexesOptions
|
|
283
|
+
): CreateIndexesOperation {
|
|
284
|
+
return new CreateIndexesOperation(parent, collectionName, indexes, options);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
static fromIndexSpecification(
|
|
288
|
+
parent: OperationParent,
|
|
289
|
+
collectionName: string,
|
|
290
|
+
indexSpec: IndexSpecification,
|
|
291
|
+
options: CreateIndexesOptions = {}
|
|
292
|
+
): CreateIndexesOperation {
|
|
293
|
+
const key = constructIndexDescriptionMap(indexSpec);
|
|
294
|
+
const description: IndexDescription = { ...options, key };
|
|
295
|
+
return new CreateIndexesOperation(parent, collectionName, [description], options);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
override get commandName() {
|
|
299
|
+
return 'createIndexes';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
override buildCommandDocument(connection: Connection): Document {
|
|
303
|
+
const options = this.options;
|
|
304
|
+
const indexes = this.indexes;
|
|
305
|
+
|
|
306
|
+
const serverWireVersion = maxWireVersion(connection);
|
|
307
|
+
|
|
308
|
+
const cmd: Document = { createIndexes: this.collectionName, indexes };
|
|
309
|
+
|
|
310
|
+
if (options.commitQuorum != null) {
|
|
311
|
+
if (serverWireVersion < 9) {
|
|
312
|
+
throw new MongoCompatibilityError(
|
|
313
|
+
'Option `commitQuorum` for `createIndexes` not supported on servers < 4.4'
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
cmd.commitQuorum = options.commitQuorum;
|
|
317
|
+
}
|
|
318
|
+
return cmd;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
override handleOk(_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): string[] {
|
|
322
|
+
const indexNames = this.indexes.map(index => index.name || '');
|
|
323
|
+
return indexNames;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** @public */
|
|
328
|
+
export type DropIndexesOptions = CommandOperationOptions;
|
|
329
|
+
|
|
330
|
+
/** @internal */
|
|
331
|
+
export class DropIndexOperation extends CommandOperation<Document> {
|
|
332
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
333
|
+
override options: DropIndexesOptions;
|
|
334
|
+
collection: Collection;
|
|
335
|
+
indexName: string;
|
|
336
|
+
|
|
337
|
+
constructor(collection: Collection, indexName: string, options?: DropIndexesOptions) {
|
|
338
|
+
super(collection, options);
|
|
339
|
+
|
|
340
|
+
this.options = options ?? {};
|
|
341
|
+
this.collection = collection;
|
|
342
|
+
this.indexName = indexName;
|
|
343
|
+
this.ns = collection.fullNamespace;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
override get commandName() {
|
|
347
|
+
return 'dropIndexes' as const;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
override buildCommandDocument(_connection: Connection): Document {
|
|
351
|
+
return { dropIndexes: this.collection.collectionName, index: this.indexName };
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** @public */
|
|
356
|
+
export type ListIndexesOptions = AbstractCursorOptions & {
|
|
357
|
+
/** @internal */
|
|
358
|
+
omitMaxTimeMS?: boolean;
|
|
359
|
+
/** @internal */
|
|
360
|
+
rawData?: boolean;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/** @internal */
|
|
364
|
+
export class ListIndexesOperation extends CommandOperation<CursorResponse> {
|
|
365
|
+
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
366
|
+
/**
|
|
367
|
+
* @remarks WriteConcern can still be present on the options because
|
|
368
|
+
* we inherit options from the client/db/collection. The
|
|
369
|
+
* key must be present on the options in order to delete it.
|
|
370
|
+
* This allows typescript to delete the key but will
|
|
371
|
+
* not allow a writeConcern to be assigned as a property on options.
|
|
372
|
+
*/
|
|
373
|
+
override options: ListIndexesOptions & { writeConcern?: never };
|
|
374
|
+
collectionNamespace: MongoDBNamespace;
|
|
375
|
+
|
|
376
|
+
constructor(collection: Collection, options?: ListIndexesOptions) {
|
|
377
|
+
super(collection, options);
|
|
378
|
+
|
|
379
|
+
this.options = { ...options };
|
|
380
|
+
delete this.options.writeConcern;
|
|
381
|
+
this.collectionNamespace = collection.s.namespace;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
override get commandName() {
|
|
385
|
+
return 'listIndexes' as const;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
override buildCommandDocument(connection: Connection): Document {
|
|
389
|
+
const serverWireVersion = maxWireVersion(connection);
|
|
390
|
+
|
|
391
|
+
const cursor = this.options.batchSize ? { batchSize: this.options.batchSize } : {};
|
|
392
|
+
|
|
393
|
+
const command: Document = { listIndexes: this.collectionNamespace.collection, cursor };
|
|
394
|
+
|
|
395
|
+
// we check for undefined specifically here to allow falsy values
|
|
396
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
397
|
+
if (serverWireVersion >= 9 && this.options.comment !== undefined) {
|
|
398
|
+
command.comment = this.options.comment;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return command;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
override handleOk(
|
|
405
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
406
|
+
): CursorResponse {
|
|
407
|
+
return response;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
defineAspects(ListIndexesOperation, [
|
|
412
|
+
Aspect.READ_OPERATION,
|
|
413
|
+
Aspect.RETRYABLE,
|
|
414
|
+
Aspect.CURSOR_CREATING,
|
|
415
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
416
|
+
]);
|
|
417
|
+
defineAspects(CreateIndexesOperation, [Aspect.WRITE_OPERATION, Aspect.SUPPORTS_RAW_DATA]);
|
|
418
|
+
defineAspects(DropIndexOperation, [Aspect.WRITE_OPERATION, Aspect.SUPPORTS_RAW_DATA]);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type Connection } from '..';
|
|
2
|
+
import type { Document } from '../bson';
|
|
3
|
+
import type { BulkWriteOptions } from '../bulk/common';
|
|
4
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
5
|
+
import type { Collection } from '../collection';
|
|
6
|
+
import { MongoServerError } from '../error';
|
|
7
|
+
import type { InferIdType } from '../mongo_types';
|
|
8
|
+
import type { ClientSession } from '../sessions';
|
|
9
|
+
import { maybeAddIdToDocuments, type MongoDBNamespace } from '../utils';
|
|
10
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
11
|
+
import { Aspect, defineAspects } from './operation';
|
|
12
|
+
/** @internal */
|
|
13
|
+
export class InsertOperation extends CommandOperation<Document> {
|
|
14
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
15
|
+
override options: BulkWriteOptions;
|
|
16
|
+
|
|
17
|
+
documents: Document[];
|
|
18
|
+
|
|
19
|
+
constructor(ns: MongoDBNamespace, documents: Document[], options: BulkWriteOptions) {
|
|
20
|
+
super(undefined, options);
|
|
21
|
+
this.options = { ...options, checkKeys: options.checkKeys ?? false };
|
|
22
|
+
this.ns = ns;
|
|
23
|
+
this.documents = documents;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override get commandName() {
|
|
27
|
+
return 'insert' as const;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
|
|
31
|
+
const options = this.options ?? {};
|
|
32
|
+
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
|
|
33
|
+
const command: Document = {
|
|
34
|
+
insert: this.ns.collection,
|
|
35
|
+
documents: this.documents,
|
|
36
|
+
ordered
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (typeof options.bypassDocumentValidation === 'boolean') {
|
|
40
|
+
command.bypassDocumentValidation = options.bypassDocumentValidation;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// we check for undefined specifically here to allow falsy values
|
|
44
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
45
|
+
if (options.comment !== undefined) {
|
|
46
|
+
command.comment = options.comment;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return command;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @public */
|
|
54
|
+
export interface InsertOneOptions extends CommandOperationOptions {
|
|
55
|
+
/** Allow driver to bypass schema validation. */
|
|
56
|
+
bypassDocumentValidation?: boolean;
|
|
57
|
+
/** Force server to assign _id values instead of driver. */
|
|
58
|
+
forceServerObjectId?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @public */
|
|
62
|
+
export interface InsertOneResult<TSchema = Document> {
|
|
63
|
+
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined */
|
|
64
|
+
acknowledged: boolean;
|
|
65
|
+
/** The identifier that was inserted. If the server generated the identifier, this value will be null as the driver does not have access to that data */
|
|
66
|
+
insertedId: InferIdType<TSchema>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class InsertOneOperation extends InsertOperation {
|
|
70
|
+
constructor(collection: Collection, doc: Document, options: InsertOneOptions) {
|
|
71
|
+
super(collection.s.namespace, [maybeAddIdToDocuments(collection, doc, options)], options);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
|
|
75
|
+
const res = super.handleOk(response);
|
|
76
|
+
if (res.code) throw new MongoServerError(res);
|
|
77
|
+
if (res.writeErrors) {
|
|
78
|
+
// This should be a WriteError but we can't change it now because of error hierarchy
|
|
79
|
+
throw new MongoServerError(res.writeErrors[0]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
acknowledged: this.writeConcern?.w !== 0,
|
|
84
|
+
insertedId: this.documents[0]._id
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @public */
|
|
90
|
+
export interface InsertManyResult<TSchema = Document> {
|
|
91
|
+
/** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined */
|
|
92
|
+
acknowledged: boolean;
|
|
93
|
+
/** The number of inserted documents for this operations */
|
|
94
|
+
insertedCount: number;
|
|
95
|
+
/** Map of the index of the inserted document to the id of the inserted document */
|
|
96
|
+
insertedIds: { [key: number]: InferIdType<TSchema> };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
defineAspects(InsertOperation, [
|
|
100
|
+
Aspect.RETRYABLE,
|
|
101
|
+
Aspect.WRITE_OPERATION,
|
|
102
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
103
|
+
]);
|
|
104
|
+
defineAspects(InsertOneOperation, [
|
|
105
|
+
Aspect.RETRYABLE,
|
|
106
|
+
Aspect.WRITE_OPERATION,
|
|
107
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
108
|
+
]);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Long } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import { type MongoError, MongoRuntimeError } from '../error';
|
|
5
|
+
import type { Server, ServerCommandOptions } from '../sdam/server';
|
|
6
|
+
import type { ClientSession } from '../sessions';
|
|
7
|
+
import { type TimeoutContext } from '../timeout';
|
|
8
|
+
import { type MongoDBNamespace } from '../utils';
|
|
9
|
+
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* https://www.mongodb.com/docs/manual/reference/command/killCursors/
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
interface KillCursorsCommand {
|
|
16
|
+
killCursors: string;
|
|
17
|
+
cursors: Long[];
|
|
18
|
+
comment?: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class KillCursorsOperation extends AbstractOperation<void> {
|
|
22
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
23
|
+
cursorId: Long;
|
|
24
|
+
|
|
25
|
+
constructor(cursorId: Long, ns: MongoDBNamespace, server: Server, options: OperationOptions) {
|
|
26
|
+
super(options);
|
|
27
|
+
this.ns = ns;
|
|
28
|
+
this.cursorId = cursorId;
|
|
29
|
+
this.server = server;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override get commandName() {
|
|
33
|
+
return 'killCursors' as const;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override buildCommand(_connection: Connection, _session?: ClientSession): KillCursorsCommand {
|
|
37
|
+
const killCursors = this.ns.collection;
|
|
38
|
+
if (killCursors == null) {
|
|
39
|
+
// Cursors should have adopted the namespace returned by MongoDB
|
|
40
|
+
// which should always defined a collection name (even a pseudo one, ex. db.aggregate())
|
|
41
|
+
throw new MongoRuntimeError('A collection name must be determined before killCursors');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const killCursorsCommand: KillCursorsCommand = {
|
|
45
|
+
killCursors,
|
|
46
|
+
cursors: [this.cursorId]
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return killCursorsCommand;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
53
|
+
return {
|
|
54
|
+
session: this.session,
|
|
55
|
+
timeoutContext
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override handleError(_error: MongoError): void {
|
|
60
|
+
// The driver should never emit errors from killCursors, this is spec-ed behavior
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
defineAspects(KillCursorsOperation, [Aspect.MUST_SELECT_SAME_SERVER]);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type Connection } from '..';
|
|
2
|
+
import type { Binary, Document } from '../bson';
|
|
3
|
+
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
|
|
4
|
+
import { type CursorTimeoutContext, type CursorTimeoutMode } from '../cursor/abstract_cursor';
|
|
5
|
+
import type { Db } from '../db';
|
|
6
|
+
import { type Abortable } from '../mongo_types';
|
|
7
|
+
import { maxWireVersion } from '../utils';
|
|
8
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
9
|
+
import { Aspect, defineAspects } from './operation';
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export interface ListCollectionsOptions
|
|
13
|
+
extends Omit<CommandOperationOptions, 'writeConcern'>,
|
|
14
|
+
Abortable {
|
|
15
|
+
/** Since 4.0: If true, will only return the collection name in the response, and will omit additional info */
|
|
16
|
+
nameOnly?: boolean;
|
|
17
|
+
/** Since 4.0: If true and nameOnly is true, allows a user without the required privilege (i.e. listCollections action on the database) to run the command when access control is enforced. */
|
|
18
|
+
authorizedCollections?: boolean;
|
|
19
|
+
/** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
|
|
20
|
+
batchSize?: number;
|
|
21
|
+
/** @internal */
|
|
22
|
+
timeoutMode?: CursorTimeoutMode;
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
timeoutContext?: CursorTimeoutContext;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @internal */
|
|
29
|
+
export class ListCollectionsOperation extends CommandOperation<CursorResponse> {
|
|
30
|
+
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
31
|
+
/**
|
|
32
|
+
* @remarks WriteConcern can still be present on the options because
|
|
33
|
+
* we inherit options from the client/db/collection. The
|
|
34
|
+
* key must be present on the options in order to delete it.
|
|
35
|
+
* This allows typescript to delete the key but will
|
|
36
|
+
* not allow a writeConcern to be assigned as a property on options.
|
|
37
|
+
*/
|
|
38
|
+
override options: ListCollectionsOptions & { writeConcern?: never };
|
|
39
|
+
db: Db;
|
|
40
|
+
filter: Document;
|
|
41
|
+
nameOnly: boolean;
|
|
42
|
+
authorizedCollections: boolean;
|
|
43
|
+
batchSize?: number;
|
|
44
|
+
|
|
45
|
+
constructor(db: Db, filter: Document, options?: ListCollectionsOptions) {
|
|
46
|
+
super(db, options);
|
|
47
|
+
|
|
48
|
+
this.options = { ...options };
|
|
49
|
+
delete this.options.writeConcern;
|
|
50
|
+
this.db = db;
|
|
51
|
+
this.filter = filter;
|
|
52
|
+
this.nameOnly = !!this.options.nameOnly;
|
|
53
|
+
this.authorizedCollections = !!this.options.authorizedCollections;
|
|
54
|
+
|
|
55
|
+
if (typeof this.options.batchSize === 'number') {
|
|
56
|
+
this.batchSize = this.options.batchSize;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.SERVER_COMMAND_RESPONSE_TYPE = this.explain ? ExplainedCursorResponse : CursorResponse;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override get commandName() {
|
|
63
|
+
return 'listCollections' as const;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override buildCommandDocument(connection: Connection): Document {
|
|
67
|
+
const command: Document = {
|
|
68
|
+
listCollections: 1,
|
|
69
|
+
filter: this.filter,
|
|
70
|
+
cursor: this.batchSize ? { batchSize: this.batchSize } : {},
|
|
71
|
+
nameOnly: this.nameOnly,
|
|
72
|
+
authorizedCollections: this.authorizedCollections
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// we check for undefined specifically here to allow falsy values
|
|
76
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
77
|
+
if (maxWireVersion(connection) >= 9 && this.options.comment !== undefined) {
|
|
78
|
+
command.comment = this.options.comment;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return command;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override handleOk(
|
|
85
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
86
|
+
): CursorResponse {
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** @public */
|
|
92
|
+
export interface CollectionInfo extends Document {
|
|
93
|
+
name: string;
|
|
94
|
+
type?: string;
|
|
95
|
+
options?: Document;
|
|
96
|
+
info?: {
|
|
97
|
+
readOnly?: false;
|
|
98
|
+
uuid?: Binary;
|
|
99
|
+
};
|
|
100
|
+
idIndex?: Document;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
defineAspects(ListCollectionsOperation, [
|
|
104
|
+
Aspect.READ_OPERATION,
|
|
105
|
+
Aspect.RETRYABLE,
|
|
106
|
+
Aspect.CURSOR_CREATING,
|
|
107
|
+
Aspect.SUPPORTS_RAW_DATA
|
|
108
|
+
]);
|