mongo 2.23.0 → 2.24.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.
- checksums.yaml +4 -4
- data/bin/mongo_console +0 -1
- data/lib/mongo/active_support.rb +1 -2
- data/lib/mongo/address/ipv4.rb +3 -6
- data/lib/mongo/address/ipv6.rb +6 -10
- data/lib/mongo/address/unix.rb +1 -4
- data/lib/mongo/address/validator.rb +16 -28
- data/lib/mongo/address.rb +30 -40
- data/lib/mongo/auth/aws/conversation.rb +6 -10
- data/lib/mongo/auth/aws/credentials.rb +0 -1
- data/lib/mongo/auth/aws/credentials_cache.rb +0 -1
- data/lib/mongo/auth/aws/credentials_retriever.rb +45 -59
- data/lib/mongo/auth/aws/request.rb +20 -35
- data/lib/mongo/auth/aws.rb +1 -2
- data/lib/mongo/auth/base.rb +20 -29
- data/lib/mongo/auth/conversation_base.rb +14 -18
- data/lib/mongo/auth/cr/conversation.rb +0 -3
- data/lib/mongo/auth/cr.rb +1 -4
- data/lib/mongo/auth/credential_cache.rb +0 -2
- data/lib/mongo/auth/gssapi/conversation.rb +3 -8
- data/lib/mongo/auth/gssapi.rb +1 -4
- data/lib/mongo/auth/ldap/conversation.rb +0 -3
- data/lib/mongo/auth/ldap.rb +1 -4
- data/lib/mongo/auth/roles.rb +16 -19
- data/lib/mongo/auth/sasl_conversation_base.rb +7 -11
- data/lib/mongo/auth/scram/conversation.rb +2 -5
- data/lib/mongo/auth/scram.rb +5 -10
- data/lib/mongo/auth/scram256/conversation.rb +2 -5
- data/lib/mongo/auth/scram256.rb +1 -3
- data/lib/mongo/auth/scram_conversation_base.rb +18 -24
- data/lib/mongo/auth/stringprep/profiles/sasl.rb +17 -18
- data/lib/mongo/auth/stringprep/tables.rb +2209 -2210
- data/lib/mongo/auth/stringprep/unicode_normalize/normalize.rb +36 -38
- data/lib/mongo/auth/stringprep/unicode_normalize/tables.rb +1142 -1150
- data/lib/mongo/auth/stringprep.rb +9 -12
- data/lib/mongo/auth/user/view.rb +3 -5
- data/lib/mongo/auth/user.rb +14 -24
- data/lib/mongo/auth/x509/conversation.rb +0 -3
- data/lib/mongo/auth/x509.rb +7 -9
- data/lib/mongo/auth.rb +18 -30
- data/lib/mongo/background_thread.rb +9 -17
- data/lib/mongo/bson.rb +0 -2
- data/lib/mongo/bulk_write/combineable.rb +0 -3
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -3
- data/lib/mongo/bulk_write/result.rb +11 -16
- data/lib/mongo/bulk_write/result_combiner.rb +9 -12
- data/lib/mongo/bulk_write/transformable.rb +16 -19
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -3
- data/lib/mongo/bulk_write/validatable.rb +11 -18
- data/lib/mongo/bulk_write.rb +76 -91
- data/lib/mongo/caching_cursor.rb +2 -7
- data/lib/mongo/client.rb +230 -275
- data/lib/mongo/client_encryption.rb +4 -5
- data/lib/mongo/cluster/periodic_executor.rb +2 -5
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +21 -29
- data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -6
- data/lib/mongo/cluster/sdam_flow.rb +136 -159
- data/lib/mongo/cluster/topology/base.rb +15 -18
- data/lib/mongo/cluster/topology/load_balanced.rb +24 -14
- data/lib/mongo/cluster/topology/no_replica_set_options.rb +3 -6
- data/lib/mongo/cluster/topology/replica_set_no_primary.rb +20 -23
- data/lib/mongo/cluster/topology/replica_set_with_primary.rb +0 -2
- data/lib/mongo/cluster/topology/sharded.rb +19 -9
- data/lib/mongo/cluster/topology/single.rb +24 -14
- data/lib/mongo/cluster/topology/unknown.rb +20 -10
- data/lib/mongo/cluster/topology.rb +29 -25
- data/lib/mongo/cluster.rb +148 -183
- data/lib/mongo/cluster_time.rb +14 -31
- data/lib/mongo/collection/helpers.rb +5 -8
- data/lib/mongo/collection/view/aggregation.rb +5 -10
- data/lib/mongo/collection/view/builder/aggregation.rb +6 -9
- data/lib/mongo/collection/view/builder/map_reduce.rb +18 -17
- data/lib/mongo/collection/view/builder.rb +0 -1
- data/lib/mongo/collection/view/change_stream/retryable.rb +3 -8
- data/lib/mongo/collection/view/change_stream.rb +59 -58
- data/lib/mongo/collection/view/explainable.rb +11 -20
- data/lib/mongo/collection/view/immutable.rb +1 -3
- data/lib/mongo/collection/view/iterable.rb +35 -28
- data/lib/mongo/collection/view/map_reduce.rb +20 -25
- data/lib/mongo/collection/view/readable.rb +50 -57
- data/lib/mongo/collection/view/writable.rb +56 -72
- data/lib/mongo/collection/view.rb +9 -8
- data/lib/mongo/collection.rb +63 -76
- data/lib/mongo/condition_variable.rb +4 -4
- data/lib/mongo/config/options.rb +0 -3
- data/lib/mongo/config/validators/option.rb +3 -5
- data/lib/mongo/config.rb +2 -4
- data/lib/mongo/crypt/auto_decryption_context.rb +0 -3
- data/lib/mongo/crypt/auto_encrypter.rb +34 -43
- data/lib/mongo/crypt/auto_encryption_context.rb +0 -3
- data/lib/mongo/crypt/binary.rb +5 -9
- data/lib/mongo/crypt/binding.rb +149 -155
- data/lib/mongo/crypt/context.rb +10 -17
- data/lib/mongo/crypt/data_key_context.rb +2 -7
- data/lib/mongo/crypt/encryption_io.rb +29 -39
- data/lib/mongo/crypt/explicit_decryption_context.rb +0 -3
- data/lib/mongo/crypt/explicit_encrypter.rb +1 -1
- data/lib/mongo/crypt/explicit_encryption_context.rb +19 -30
- data/lib/mongo/crypt/explicit_encryption_expression_context.rb +0 -2
- data/lib/mongo/crypt/handle.rb +42 -48
- data/lib/mongo/crypt/hooks.rb +12 -15
- data/lib/mongo/crypt/kms/aws/credentials.rb +12 -16
- data/lib/mongo/crypt/kms/aws/master_document.rb +6 -9
- data/lib/mongo/crypt/kms/aws.rb +0 -2
- data/lib/mongo/crypt/kms/azure/credentials_retriever.rb +2 -7
- data/lib/mongo/crypt/kms/azure/master_document.rb +15 -19
- data/lib/mongo/crypt/kms/azure.rb +0 -1
- data/lib/mongo/crypt/kms/credentials.rb +13 -27
- data/lib/mongo/crypt/kms/gcp/credentials.rb +12 -14
- data/lib/mongo/crypt/kms/gcp/credentials_retriever.rb +7 -9
- data/lib/mongo/crypt/kms/gcp/master_document.rb +12 -16
- data/lib/mongo/crypt/kms/gcp.rb +0 -2
- data/lib/mongo/crypt/kms/kmip/credentials.rb +7 -8
- data/lib/mongo/crypt/kms/kmip/master_document.rb +3 -5
- data/lib/mongo/crypt/kms/kmip.rb +0 -1
- data/lib/mongo/crypt/kms/local/credentials.rb +7 -8
- data/lib/mongo/crypt/kms/local/master_document.rb +2 -6
- data/lib/mongo/crypt/kms/local.rb +0 -1
- data/lib/mongo/crypt/kms/master_key_document.rb +11 -15
- data/lib/mongo/crypt/kms.rb +14 -16
- data/lib/mongo/crypt/kms_context.rb +0 -2
- data/lib/mongo/crypt/rewrap_many_data_key_context.rb +2 -7
- data/lib/mongo/crypt/rewrap_many_data_key_result.rb +2 -4
- data/lib/mongo/crypt/status.rb +12 -14
- data/lib/mongo/crypt.rb +0 -1
- data/lib/mongo/csot_timeout_holder.rb +3 -2
- data/lib/mongo/cursor/kill_spec.rb +7 -10
- data/lib/mongo/cursor.rb +74 -64
- data/lib/mongo/cursor_host.rb +8 -10
- data/lib/mongo/database/view.rb +16 -37
- data/lib/mongo/database.rb +52 -56
- data/lib/mongo/dbref.rb +0 -1
- data/lib/mongo/distinguishing_semaphore.rb +0 -1
- data/lib/mongo/error/auth_error.rb +0 -2
- data/lib/mongo/error/bad_load_balancer_target.rb +0 -2
- data/lib/mongo/error/bulk_write_error.rb +7 -10
- data/lib/mongo/error/change_stream_resumable.rb +0 -2
- data/lib/mongo/error/client_closed.rb +0 -2
- data/lib/mongo/error/closed_stream.rb +1 -4
- data/lib/mongo/error/connection_check_out_timeout.rb +3 -6
- data/lib/mongo/error/connection_perished.rb +0 -2
- data/lib/mongo/error/connection_unavailable.rb +0 -2
- data/lib/mongo/error/credential_check_error.rb +0 -2
- data/lib/mongo/error/crypt_error.rb +0 -2
- data/lib/mongo/error/extra_file_chunk.rb +1 -4
- data/lib/mongo/error/failed_string_prep_validation.rb +5 -6
- data/lib/mongo/error/file_not_found.rb +0 -3
- data/lib/mongo/error/handshake_error.rb +0 -2
- data/lib/mongo/error/insufficient_iteration_count.rb +1 -4
- data/lib/mongo/error/internal_driver_error.rb +0 -2
- data/lib/mongo/error/invalid_address.rb +0 -2
- data/lib/mongo/error/invalid_application_name.rb +0 -3
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -4
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -4
- data/lib/mongo/error/invalid_collection_name.rb +1 -4
- data/lib/mongo/error/invalid_config_option.rb +0 -3
- data/lib/mongo/error/invalid_cursor_operation.rb +0 -2
- data/lib/mongo/error/invalid_database_name.rb +1 -4
- data/lib/mongo/error/invalid_document.rb +1 -4
- data/lib/mongo/error/invalid_file.rb +0 -3
- data/lib/mongo/error/invalid_file_revision.rb +0 -3
- data/lib/mongo/error/invalid_min_pool_size.rb +0 -3
- data/lib/mongo/error/invalid_nonce.rb +0 -3
- data/lib/mongo/error/invalid_read_concern.rb +2 -4
- data/lib/mongo/error/invalid_read_option.rb +0 -3
- data/lib/mongo/error/invalid_replacement_document.rb +2 -5
- data/lib/mongo/error/invalid_server_auth_host.rb +0 -2
- data/lib/mongo/error/invalid_server_auth_response.rb +0 -2
- data/lib/mongo/error/invalid_server_preference.rb +7 -16
- data/lib/mongo/error/invalid_session.rb +1 -4
- data/lib/mongo/error/invalid_signature.rb +0 -3
- data/lib/mongo/error/invalid_transaction_operation.rb +5 -8
- data/lib/mongo/error/invalid_txt_record.rb +0 -2
- data/lib/mongo/error/invalid_update_document.rb +2 -5
- data/lib/mongo/error/invalid_uri.rb +1 -4
- data/lib/mongo/error/invalid_write_concern.rb +2 -5
- data/lib/mongo/error/kms_error.rb +0 -2
- data/lib/mongo/error/labelable.rb +0 -3
- data/lib/mongo/error/lint_error.rb +0 -2
- data/lib/mongo/error/max_bson_size.rb +8 -11
- data/lib/mongo/error/max_message_size.rb +2 -5
- data/lib/mongo/error/mismatched_domain.rb +0 -2
- data/lib/mongo/error/missing_connection.rb +0 -2
- data/lib/mongo/error/missing_file_chunk.rb +0 -3
- data/lib/mongo/error/missing_password.rb +0 -2
- data/lib/mongo/error/missing_resume_token.rb +1 -4
- data/lib/mongo/error/missing_scram_server_signature.rb +2 -4
- data/lib/mongo/error/missing_service_id.rb +0 -2
- data/lib/mongo/error/mongocryptd_spawn_error.rb +0 -2
- data/lib/mongo/error/multi_index_drop.rb +0 -3
- data/lib/mongo/error/need_primary_server.rb +0 -2
- data/lib/mongo/error/no_server_available.rb +3 -8
- data/lib/mongo/error/no_service_connection_available.rb +1 -3
- data/lib/mongo/error/no_srv_records.rb +0 -2
- data/lib/mongo/error/notable.rb +8 -16
- data/lib/mongo/error/operation_failure.rb +22 -35
- data/lib/mongo/error/parser.rb +33 -75
- data/lib/mongo/error/pool_cleared_error.rb +1 -3
- data/lib/mongo/error/pool_closed_error.rb +0 -3
- data/lib/mongo/error/pool_error.rb +0 -3
- data/lib/mongo/error/pool_paused_error.rb +0 -2
- data/lib/mongo/error/raise_original_error.rb +1 -3
- data/lib/mongo/error/read_write_retryable.rb +14 -17
- data/lib/mongo/error/sdam_error_detection.rb +3 -5
- data/lib/mongo/error/server_api_conflict.rb +0 -2
- data/lib/mongo/error/server_certificate_revoked.rb +0 -2
- data/lib/mongo/error/server_not_usable.rb +0 -2
- data/lib/mongo/error/session_ended.rb +1 -3
- data/lib/mongo/error/session_not_materialized.rb +1 -3
- data/lib/mongo/error/sessions_not_supported.rb +1 -4
- data/lib/mongo/error/snapshot_session_invalid_server_version.rb +1 -4
- data/lib/mongo/error/snapshot_session_transaction_prohibited.rb +1 -4
- data/lib/mongo/error/socket_error.rb +0 -2
- data/lib/mongo/error/socket_timeout_error.rb +0 -2
- data/lib/mongo/error/transactions_not_supported.rb +3 -6
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -4
- data/lib/mongo/error/unexpected_chunk_length.rb +0 -3
- data/lib/mongo/error/unexpected_response.rb +1 -4
- data/lib/mongo/error/unknown_payload_type.rb +0 -3
- data/lib/mongo/error/unmet_dependency.rb +0 -2
- data/lib/mongo/error/unsupported_array_filters.rb +3 -24
- data/lib/mongo/error/unsupported_collation.rb +3 -24
- data/lib/mongo/error/unsupported_features.rb +0 -2
- data/lib/mongo/error/unsupported_message_type.rb +0 -2
- data/lib/mongo/error/unsupported_option.rb +19 -21
- data/lib/mongo/error/write_retryable.rb +0 -2
- data/lib/mongo/error.rb +10 -24
- data/lib/mongo/event/base.rb +0 -2
- data/lib/mongo/event/listeners.rb +0 -3
- data/lib/mongo/event/publisher.rb +0 -3
- data/lib/mongo/event/subscriber.rb +0 -4
- data/lib/mongo/event.rb +4 -6
- data/lib/mongo/grid/file/chunk.rb +7 -10
- data/lib/mongo/grid/file/info.rb +20 -24
- data/lib/mongo/grid/file.rb +7 -8
- data/lib/mongo/grid/fs_bucket.rb +40 -48
- data/lib/mongo/grid/stream/read.rb +25 -35
- data/lib/mongo/grid/stream/write.rb +17 -22
- data/lib/mongo/grid/stream.rb +2 -4
- data/lib/mongo/grid.rb +0 -1
- data/lib/mongo/id.rb +0 -1
- data/lib/mongo/index/view.rb +49 -48
- data/lib/mongo/index.rb +7 -10
- data/lib/mongo/lint.rb +31 -37
- data/lib/mongo/loggable.rb +5 -8
- data/lib/mongo/logger.rb +1 -7
- data/lib/mongo/monitoring/cmap_log_subscriber.rb +0 -2
- data/lib/mongo/monitoring/command_log_subscriber.rb +25 -33
- data/lib/mongo/monitoring/event/cmap/base.rb +0 -2
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +0 -3
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +2 -5
- data/lib/mongo/monitoring/event/cmap/connection_closed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_created.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_ready.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +0 -3
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_ready.rb +1 -4
- data/lib/mongo/monitoring/event/cmap.rb +0 -1
- data/lib/mongo/monitoring/event/command_failed.rb +5 -9
- data/lib/mongo/monitoring/event/command_started.rb +8 -12
- data/lib/mongo/monitoring/event/command_succeeded.rb +7 -15
- data/lib/mongo/monitoring/event/secure.rb +15 -20
- data/lib/mongo/monitoring/event/server_closed.rb +1 -4
- data/lib/mongo/monitoring/event/server_description_changed.rb +4 -8
- data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +5 -10
- data/lib/mongo/monitoring/event/server_heartbeat_started.rb +1 -4
- data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +3 -8
- data/lib/mongo/monitoring/event/server_opening.rb +1 -4
- data/lib/mongo/monitoring/event/topology_changed.rb +2 -5
- data/lib/mongo/monitoring/event/topology_closed.rb +1 -4
- data/lib/mongo/monitoring/event/topology_opening.rb +1 -4
- data/lib/mongo/monitoring/event.rb +0 -1
- data/lib/mongo/monitoring/publishable.rb +20 -30
- data/lib/mongo/monitoring/sdam_log_subscriber.rb +0 -2
- data/lib/mongo/monitoring/server_closed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/server_opening_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +5 -8
- data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +1 -3
- data/lib/mongo/monitoring.rb +38 -39
- data/lib/mongo/operation/aggregate/op_msg.rb +0 -2
- data/lib/mongo/operation/aggregate/result.rb +3 -6
- data/lib/mongo/operation/aggregate.rb +0 -2
- data/lib/mongo/operation/collections_info/result.rb +0 -3
- data/lib/mongo/operation/collections_info.rb +0 -2
- data/lib/mongo/operation/command/op_msg.rb +1 -4
- data/lib/mongo/operation/command.rb +0 -2
- data/lib/mongo/operation/context.rb +13 -16
- data/lib/mongo/operation/count/op_msg.rb +2 -4
- data/lib/mongo/operation/count.rb +0 -2
- data/lib/mongo/operation/create/op_msg.rb +2 -5
- data/lib/mongo/operation/create.rb +0 -2
- data/lib/mongo/operation/create_index/op_msg.rb +3 -7
- data/lib/mongo/operation/create_index.rb +0 -2
- data/lib/mongo/operation/create_user/op_msg.rb +2 -4
- data/lib/mongo/operation/create_user.rb +0 -2
- data/lib/mongo/operation/delete/bulk_result.rb +2 -3
- data/lib/mongo/operation/delete/op_msg.rb +3 -10
- data/lib/mongo/operation/delete/result.rb +0 -3
- data/lib/mongo/operation/delete.rb +1 -5
- data/lib/mongo/operation/distinct/op_msg.rb +2 -5
- data/lib/mongo/operation/distinct.rb +0 -2
- data/lib/mongo/operation/drop/op_msg.rb +0 -2
- data/lib/mongo/operation/drop.rb +0 -2
- data/lib/mongo/operation/drop_database/op_msg.rb +0 -2
- data/lib/mongo/operation/drop_database.rb +0 -2
- data/lib/mongo/operation/drop_index/op_msg.rb +4 -6
- data/lib/mongo/operation/drop_index.rb +0 -2
- data/lib/mongo/operation/explain/op_msg.rb +0 -2
- data/lib/mongo/operation/explain/result.rb +0 -3
- data/lib/mongo/operation/explain.rb +0 -2
- data/lib/mongo/operation/find/builder/command.rb +4 -12
- data/lib/mongo/operation/find/builder/flags.rb +9 -15
- data/lib/mongo/operation/find/builder/modifiers.rb +1 -4
- data/lib/mongo/operation/find/builder.rb +0 -1
- data/lib/mongo/operation/find/op_msg.rb +4 -12
- data/lib/mongo/operation/find/result.rb +0 -3
- data/lib/mongo/operation/find.rb +0 -2
- data/lib/mongo/operation/get_more/command_builder.rb +1 -6
- data/lib/mongo/operation/get_more/op_msg.rb +10 -4
- data/lib/mongo/operation/get_more/result.rb +0 -3
- data/lib/mongo/operation/get_more.rb +0 -2
- data/lib/mongo/operation/indexes/op_msg.rb +0 -2
- data/lib/mongo/operation/indexes/result.rb +1 -5
- data/lib/mongo/operation/indexes.rb +0 -2
- data/lib/mongo/operation/insert/bulk_result.rb +2 -6
- data/lib/mongo/operation/insert/op_msg.rb +2 -4
- data/lib/mongo/operation/insert/result.rb +0 -3
- data/lib/mongo/operation/insert.rb +2 -5
- data/lib/mongo/operation/kill_cursors/command_builder.rb +0 -3
- data/lib/mongo/operation/kill_cursors/op_msg.rb +1 -3
- data/lib/mongo/operation/kill_cursors.rb +0 -2
- data/lib/mongo/operation/list_collections/op_msg.rb +4 -6
- data/lib/mongo/operation/list_collections/result.rb +1 -4
- data/lib/mongo/operation/list_collections.rb +0 -2
- data/lib/mongo/operation/map_reduce/op_msg.rb +0 -2
- data/lib/mongo/operation/map_reduce/result.rb +3 -6
- data/lib/mongo/operation/map_reduce.rb +0 -2
- data/lib/mongo/operation/op_msg_base.rb +0 -1
- data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -5
- data/lib/mongo/operation/parallel_scan/result.rb +2 -5
- data/lib/mongo/operation/parallel_scan.rb +0 -2
- data/lib/mongo/operation/remove_user/op_msg.rb +2 -4
- data/lib/mongo/operation/remove_user.rb +0 -2
- data/lib/mongo/operation/result.rb +38 -48
- data/lib/mongo/operation/shared/bypass_document_validation.rb +3 -7
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +0 -3
- data/lib/mongo/operation/shared/executable.rb +19 -28
- data/lib/mongo/operation/shared/executable_no_validate.rb +0 -3
- data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -2
- data/lib/mongo/operation/shared/idable.rb +3 -6
- data/lib/mongo/operation/shared/limited.rb +0 -3
- data/lib/mongo/operation/shared/object_id_generator.rb +0 -3
- data/lib/mongo/operation/shared/op_msg_executable.rb +0 -2
- data/lib/mongo/operation/shared/polymorphic_lookup.rb +0 -2
- data/lib/mongo/operation/shared/polymorphic_result.rb +2 -4
- data/lib/mongo/operation/shared/read_preference_supported.rb +10 -15
- data/lib/mongo/operation/shared/response_handling.rb +13 -26
- data/lib/mongo/operation/shared/result/aggregatable.rb +12 -13
- data/lib/mongo/operation/shared/sessions_supported.rb +87 -99
- data/lib/mongo/operation/shared/specifiable.rb +32 -58
- data/lib/mongo/operation/shared/write.rb +12 -17
- data/lib/mongo/operation/shared/write_concern_supported.rb +4 -7
- data/lib/mongo/operation/update/bulk_result.rb +13 -17
- data/lib/mongo/operation/update/op_msg.rb +2 -5
- data/lib/mongo/operation/update/result.rb +5 -5
- data/lib/mongo/operation/update.rb +1 -5
- data/lib/mongo/operation/update_user/op_msg.rb +2 -4
- data/lib/mongo/operation/update_user.rb +0 -2
- data/lib/mongo/operation/users_info/op_msg.rb +2 -4
- data/lib/mongo/operation/users_info/result.rb +1 -4
- data/lib/mongo/operation/users_info.rb +0 -2
- data/lib/mongo/operation/write_command/op_msg.rb +2 -10
- data/lib/mongo/operation/write_command.rb +0 -2
- data/lib/mongo/operation.rb +9 -14
- data/lib/mongo/options/mapper.rb +8 -15
- data/lib/mongo/options/redacted.rb +7 -9
- data/lib/mongo/options.rb +0 -1
- data/lib/mongo/protocol/bit_vector.rb +3 -5
- data/lib/mongo/protocol/caching_hash.rb +2 -7
- data/lib/mongo/protocol/compressed.rb +5 -10
- data/lib/mongo/protocol/get_more.rb +2 -8
- data/lib/mongo/protocol/kill_cursors.rb +2 -8
- data/lib/mongo/protocol/message.rb +103 -105
- data/lib/mongo/protocol/msg.rb +48 -63
- data/lib/mongo/protocol/query.rb +32 -41
- data/lib/mongo/protocol/registry.rb +2 -5
- data/lib/mongo/protocol/reply.rb +10 -16
- data/lib/mongo/protocol/serializers.rb +41 -59
- data/lib/mongo/protocol.rb +0 -1
- data/lib/mongo/query_cache.rb +7 -15
- data/lib/mongo/retryable/backpressure.rb +31 -0
- data/lib/mongo/retryable/base_worker.rb +39 -13
- data/lib/mongo/retryable/read_worker.rb +77 -21
- data/lib/mongo/retryable/retry_policy.rb +59 -0
- data/lib/mongo/retryable/write_worker.rb +155 -56
- data/lib/mongo/retryable.rb +70 -9
- data/lib/mongo/search_index/view.rb +1 -1
- data/lib/mongo/semaphore.rb +0 -1
- data/lib/mongo/server/app_metadata/environment.rb +3 -3
- data/lib/mongo/server/app_metadata.rb +4 -5
- data/lib/mongo/server/connection.rb +61 -61
- data/lib/mongo/server/connection_base.rb +43 -53
- data/lib/mongo/server/connection_common.rb +41 -64
- data/lib/mongo/server/connection_pool/generation_manager.rb +6 -11
- data/lib/mongo/server/connection_pool/populator.rb +1 -4
- data/lib/mongo/server/connection_pool.rb +195 -167
- data/lib/mongo/server/description/features.rb +23 -60
- data/lib/mongo/server/description/load_balancer.rb +0 -2
- data/lib/mongo/server/description.rb +117 -138
- data/lib/mongo/server/monitor/app_metadata.rb +3 -4
- data/lib/mongo/server/monitor/connection.rb +28 -35
- data/lib/mongo/server/monitor.rb +65 -60
- data/lib/mongo/server/pending_connection.rb +70 -71
- data/lib/mongo/server/push_monitor/connection.rb +0 -3
- data/lib/mongo/server/push_monitor.rb +21 -29
- data/lib/mongo/server/round_trip_time_calculator.rb +11 -17
- data/lib/mongo/server.rb +60 -93
- data/lib/mongo/server_selector/base.rb +133 -157
- data/lib/mongo/server_selector/nearest.rb +2 -5
- data/lib/mongo/server_selector/primary.rb +1 -5
- data/lib/mongo/server_selector/primary_preferred.rb +2 -6
- data/lib/mongo/server_selector/secondary.rb +2 -6
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -5
- data/lib/mongo/server_selector.rb +3 -4
- data/lib/mongo/session/server_session.rb +6 -7
- data/lib/mongo/session/session_pool.rb +20 -34
- data/lib/mongo/session.rb +287 -188
- data/lib/mongo/socket/ocsp_cache.rb +8 -13
- data/lib/mongo/socket/ocsp_verifier.rb +69 -70
- data/lib/mongo/socket/ssl.rb +44 -43
- data/lib/mongo/socket/tcp.rb +5 -8
- data/lib/mongo/socket/unix.rb +0 -4
- data/lib/mongo/socket.rb +80 -102
- data/lib/mongo/srv/monitor.rb +6 -11
- data/lib/mongo/srv/resolver.rb +15 -24
- data/lib/mongo/srv/result.rb +18 -24
- data/lib/mongo/srv.rb +0 -1
- data/lib/mongo/timeout.rb +4 -11
- data/lib/mongo/topology_version.rb +8 -13
- data/lib/mongo/tracing/open_telemetry/command_tracer.rb +1 -1
- data/lib/mongo/tracing/open_telemetry/operation_tracer.rb +1 -1
- data/lib/mongo/tracing/open_telemetry/tracer.rb +1 -1
- data/lib/mongo/uri/options_mapper.rb +135 -126
- data/lib/mongo/uri/srv_protocol.rb +25 -38
- data/lib/mongo/uri.rb +95 -139
- data/lib/mongo/utils.rb +5 -12
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/acknowledged.rb +0 -2
- data/lib/mongo/write_concern/base.rb +6 -6
- data/lib/mongo/write_concern/unacknowledged.rb +0 -2
- data/lib/mongo/write_concern.rb +14 -15
- data/lib/mongo.rb +1 -3
- data/mongo.gemspec +17 -17
- metadata +5 -5
- data/lib/mongo/error/server_api_not_supported.rb +0 -27
- data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +0 -32
- data/lib/mongo/operation/shared/validatable.rb +0 -87
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -20,7 +19,6 @@ require 'mongo/cursor_host'
|
|
|
20
19
|
module Mongo
|
|
21
20
|
class Collection
|
|
22
21
|
class View
|
|
23
|
-
|
|
24
22
|
# Defines iteration related behavior for collection views, including
|
|
25
23
|
# cursor instantiation.
|
|
26
24
|
#
|
|
@@ -40,23 +38,22 @@ module Mongo
|
|
|
40
38
|
# @since 2.0.0
|
|
41
39
|
#
|
|
42
40
|
# @yieldparam [ Hash ] Each matching document.
|
|
43
|
-
def each
|
|
41
|
+
def each(&block)
|
|
44
42
|
@cursor = prefer_cached_cursor? ? cached_cursor : new_cursor_for_iteration
|
|
45
43
|
return @cursor.to_enum unless block_given?
|
|
46
44
|
|
|
47
45
|
limit_for_cached_query = compute_limit_for_cached_query
|
|
48
46
|
|
|
49
|
-
#
|
|
50
|
-
# this
|
|
47
|
+
# TODO: rather than pulling the entire (limited) result set into
|
|
48
|
+
# memory, this should tell the cursor about the limit and then let
|
|
49
|
+
# the cursor limit the iteration as necessary.
|
|
51
50
|
cursor_to_iterate = if limit_for_cached_query
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
@cursor.to_a[0...limit_for_cached_query]
|
|
52
|
+
else
|
|
53
|
+
@cursor
|
|
54
|
+
end
|
|
56
55
|
|
|
57
|
-
cursor_to_iterate.each
|
|
58
|
-
yield doc
|
|
59
|
-
end
|
|
56
|
+
cursor_to_iterate.each(&block)
|
|
60
57
|
end
|
|
61
58
|
|
|
62
59
|
# Cleans up resources associated with this query.
|
|
@@ -73,11 +70,11 @@ module Mongo
|
|
|
73
70
|
#
|
|
74
71
|
# @since 2.1.0
|
|
75
72
|
def close_query
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
return unless @cursor
|
|
74
|
+
|
|
75
|
+
@cursor.close
|
|
79
76
|
end
|
|
80
|
-
alias
|
|
77
|
+
alias kill_cursors close_query
|
|
81
78
|
|
|
82
79
|
private
|
|
83
80
|
|
|
@@ -91,13 +88,16 @@ module Mongo
|
|
|
91
88
|
op = initial_query_op(session)
|
|
92
89
|
tracer.trace_operation(op, context) do
|
|
93
90
|
if respond_to?(:write?, true) && write?
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
retry_enabled = collection.client.options[:retry_writes] != false
|
|
92
|
+
with_overload_retry(context: context, retry_enabled: retry_enabled) do
|
|
93
|
+
server = server_selector.select_server(cluster, nil, session, write_aggregation: true)
|
|
94
|
+
result = send_initial_query(server, context, operation: op)
|
|
95
|
+
|
|
96
|
+
if use_query_cache?
|
|
97
|
+
CachingCursor.new(view, result, server, session: session, context: context)
|
|
98
|
+
else
|
|
99
|
+
Cursor.new(view, result, server, session: session, context: context)
|
|
100
|
+
end
|
|
101
101
|
end
|
|
102
102
|
else
|
|
103
103
|
read_with_retry_cursor(session, server_selector, view, context: context) do |server|
|
|
@@ -156,7 +156,7 @@ module Mongo
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
if spec[:oplog_replay]
|
|
159
|
-
collection.client.log_warn(
|
|
159
|
+
collection.client.log_warn('The :oplog_replay option is deprecated and ignored by MongoDB 4.4 and later')
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
maybe_set_tailable_options(spec)
|
|
@@ -172,8 +172,15 @@ module Mongo
|
|
|
172
172
|
def send_initial_query(server, context, operation: nil)
|
|
173
173
|
operation ||= initial_query_op(context.session)
|
|
174
174
|
if server.load_balancer?
|
|
175
|
-
# Connection will be checked in when cursor is drained
|
|
176
|
-
connection
|
|
175
|
+
# Connection will be checked in when cursor is drained,
|
|
176
|
+
# unless the connection is pinned to a transaction (in which
|
|
177
|
+
# case it stays checked out for the transaction duration).
|
|
178
|
+
if context.connection_global_id
|
|
179
|
+
connection = server.pool.check_out_pinned_connection(
|
|
180
|
+
context.connection_global_id
|
|
181
|
+
)
|
|
182
|
+
end
|
|
183
|
+
connection ||= server.pool.check_out(context: context)
|
|
177
184
|
operation.execute_with_connection(connection, context: context)
|
|
178
185
|
else
|
|
179
186
|
operation.execute(server, context: context)
|
|
@@ -212,10 +219,10 @@ module Mongo
|
|
|
212
219
|
# If a query with a limit is performed, the query cache will
|
|
213
220
|
# re-use results from an earlier query with the same or larger
|
|
214
221
|
# limit, and then impose the lower limit during iteration.
|
|
215
|
-
|
|
222
|
+
QueryCache.normalized_limit(limit)
|
|
216
223
|
end
|
|
217
224
|
|
|
218
|
-
# Add tailable
|
|
225
|
+
# Add tailable cursor options to the command specification if needed.
|
|
219
226
|
#
|
|
220
227
|
# @param [ Hash ] spec The command specification.
|
|
221
228
|
def maybe_set_tailable_options(spec)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -18,7 +17,6 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
|
-
|
|
22
20
|
# Provides behavior around a map/reduce operation on the collection
|
|
23
21
|
# view.
|
|
24
22
|
#
|
|
@@ -33,13 +31,13 @@ module Mongo
|
|
|
33
31
|
# The inline option.
|
|
34
32
|
#
|
|
35
33
|
# @since 2.1.0
|
|
36
|
-
INLINE = 'inline'
|
|
34
|
+
INLINE = 'inline'
|
|
37
35
|
|
|
38
36
|
# Reroute message.
|
|
39
37
|
#
|
|
40
38
|
# @since 2.1.0
|
|
41
39
|
# @deprecated
|
|
42
|
-
REROUTE = 'Rerouting the MapReduce operation to the primary server
|
|
40
|
+
REROUTE = 'Rerouting the MapReduce operation to the primary server'
|
|
43
41
|
|
|
44
42
|
# @return [ View ] view The collection view.
|
|
45
43
|
attr_reader :view
|
|
@@ -68,11 +66,12 @@ module Mongo
|
|
|
68
66
|
# @since 2.0.0
|
|
69
67
|
#
|
|
70
68
|
# @yieldparam [ Hash ] Each matching document.
|
|
71
|
-
def each
|
|
69
|
+
def each(&block)
|
|
72
70
|
@cursor = nil
|
|
73
71
|
session = client.get_session(@options)
|
|
74
72
|
server = cluster.next_primary(nil, session)
|
|
75
|
-
context = Operation::Context.new(client: client, session: session,
|
|
73
|
+
context = Operation::Context.new(client: client, session: session,
|
|
74
|
+
operation_timeouts: view.operation_timeouts)
|
|
76
75
|
if server.load_balancer?
|
|
77
76
|
# Connection will be checked in when cursor is drained.
|
|
78
77
|
connection = server.pool.check_out(context: context)
|
|
@@ -84,9 +83,7 @@ module Mongo
|
|
|
84
83
|
end
|
|
85
84
|
@cursor = Cursor.new(view, result, server, session: session)
|
|
86
85
|
if block_given?
|
|
87
|
-
@cursor.each
|
|
88
|
-
yield doc
|
|
89
|
-
end
|
|
86
|
+
@cursor.each(&block)
|
|
90
87
|
else
|
|
91
88
|
@cursor.to_enum
|
|
92
89
|
end
|
|
@@ -124,7 +121,8 @@ module Mongo
|
|
|
124
121
|
@reduce_function = reduce.dup.freeze
|
|
125
122
|
@options = BSON::Document.new(options).freeze
|
|
126
123
|
|
|
127
|
-
|
|
124
|
+
Deprecations.warn(:map_reduce,
|
|
125
|
+
'The map_reduce operation is deprecated, please use the aggregation pipeline instead.')
|
|
128
126
|
end
|
|
129
127
|
|
|
130
128
|
# Set or get the jsMode flag for the operation.
|
|
@@ -179,12 +177,12 @@ module Mongo
|
|
|
179
177
|
# Returns the database name where the map-reduce result is written to.
|
|
180
178
|
# If the result is returned inline, returns nil.
|
|
181
179
|
def out_database_name
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
180
|
+
return unless options[:out]
|
|
181
|
+
|
|
182
|
+
if options[:out].respond_to?(:keys) && (db = options[:out][:db])
|
|
183
|
+
db
|
|
184
|
+
else
|
|
185
|
+
database.name
|
|
188
186
|
end
|
|
189
187
|
end
|
|
190
188
|
|
|
@@ -232,7 +230,7 @@ module Mongo
|
|
|
232
230
|
view.send(:with_session, @options) do |session|
|
|
233
231
|
write_concern = view.write_concern_with_session(session)
|
|
234
232
|
context = Operation::Context.new(client: client, session: session)
|
|
235
|
-
nro_write_with_retry(write_concern, context: context) do |connection,
|
|
233
|
+
nro_write_with_retry(write_concern, context: context) do |connection, _txn_num, context|
|
|
236
234
|
send_initial_query_with_connection(connection, session, context: context)
|
|
237
235
|
end
|
|
238
236
|
end
|
|
@@ -240,7 +238,7 @@ module Mongo
|
|
|
240
238
|
|
|
241
239
|
private
|
|
242
240
|
|
|
243
|
-
OUT_ACTIONS = [
|
|
241
|
+
OUT_ACTIONS = %i[replace merge reduce].freeze
|
|
244
242
|
|
|
245
243
|
def server_selector
|
|
246
244
|
@view.send(:server_selector)
|
|
@@ -276,11 +274,7 @@ module Mongo
|
|
|
276
274
|
end
|
|
277
275
|
|
|
278
276
|
def valid_server?(description)
|
|
279
|
-
|
|
280
|
-
true
|
|
281
|
-
else
|
|
282
|
-
description.standalone? || description.mongos? || description.primary? || description.load_balancer?
|
|
283
|
-
end
|
|
277
|
+
secondary_ok? || description.standalone? || description.mongos? || description.primary? || description.load_balancer?
|
|
284
278
|
end
|
|
285
279
|
|
|
286
280
|
def secondary_ok?
|
|
@@ -298,7 +292,7 @@ module Mongo
|
|
|
298
292
|
if valid_server?(connection.description)
|
|
299
293
|
op.execute_with_connection(connection, context: context)
|
|
300
294
|
else
|
|
301
|
-
msg = "
|
|
295
|
+
msg = "#{REROUTE} - #{connection.address} is not suitable because it is not currently the primary"
|
|
302
296
|
log_warn(msg)
|
|
303
297
|
server = cluster.next_primary(nil, session)
|
|
304
298
|
op.execute(server, context: context)
|
|
@@ -310,7 +304,8 @@ module Mongo
|
|
|
310
304
|
end
|
|
311
305
|
|
|
312
306
|
def find_command_spec(session)
|
|
313
|
-
Builder::MapReduce.new(map_function, reduce_function, view,
|
|
307
|
+
Builder::MapReduce.new(map_function, reduce_function, view,
|
|
308
|
+
options.merge(session: session)).command_specification
|
|
314
309
|
end
|
|
315
310
|
|
|
316
311
|
def fetch_query_op(session)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -18,12 +17,10 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
|
-
|
|
22
20
|
# Defines read related behavior for collection view.
|
|
23
21
|
#
|
|
24
22
|
# @since 2.0.0
|
|
25
23
|
module Readable
|
|
26
|
-
|
|
27
24
|
# Execute an aggregation on the collection view.
|
|
28
25
|
#
|
|
29
26
|
# @example Aggregate documents.
|
|
@@ -169,18 +166,19 @@ module Mongo
|
|
|
169
166
|
#
|
|
170
167
|
# @deprecated Use #count_documents or #estimated_document_count instead. However, note that
|
|
171
168
|
# the following operators will need to be substituted when switching to #count_documents:
|
|
172
|
-
# * $where should be replaced with $expr
|
|
169
|
+
# * $where should be replaced with $expr
|
|
173
170
|
# * $near should be replaced with $geoWithin with $center
|
|
174
171
|
# * $nearSphere should be replaced with $geoWithin with $centerSphere
|
|
175
172
|
def count(opts = {})
|
|
176
173
|
opts = @options.merge(opts) unless Mongo.broken_view_options
|
|
177
|
-
cmd = { :
|
|
174
|
+
cmd = { count: collection.name, query: filter }
|
|
178
175
|
cmd[:skip] = opts[:skip] if opts[:skip]
|
|
179
176
|
cmd[:hint] = opts[:hint] if opts[:hint]
|
|
180
177
|
cmd[:limit] = opts[:limit] if opts[:limit]
|
|
181
178
|
if read_concern
|
|
182
179
|
cmd[:readConcern] = Options::Mapper.transform_values_to_strings(
|
|
183
|
-
read_concern
|
|
180
|
+
read_concern
|
|
181
|
+
)
|
|
184
182
|
end
|
|
185
183
|
cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
|
|
186
184
|
Mongo::Lint.validate_underscore_read_preference(opts[:read])
|
|
@@ -195,13 +193,13 @@ module Mongo
|
|
|
195
193
|
operation = Operation::Count.new(
|
|
196
194
|
selector: cmd,
|
|
197
195
|
db_name: database.name,
|
|
198
|
-
options: {:
|
|
196
|
+
options: { limit: -1 },
|
|
199
197
|
read: read_pref,
|
|
200
198
|
session: session,
|
|
201
199
|
# For some reason collation was historically accepted as a
|
|
202
200
|
# string key. Note that this isn't documented as valid usage.
|
|
203
201
|
collation: opts[:collation] || opts['collation'] || collation,
|
|
204
|
-
comment: opts[:comment]
|
|
202
|
+
comment: opts[:comment]
|
|
205
203
|
)
|
|
206
204
|
tracer.trace_operation(operation, context) do
|
|
207
205
|
read_with_retry(session, selector, context) do |server|
|
|
@@ -223,7 +221,7 @@ module Mongo
|
|
|
223
221
|
#
|
|
224
222
|
# @option opts :skip [ Integer ] The number of documents to skip.
|
|
225
223
|
# @option opts :hint [ Hash ] Override default index selection and force
|
|
226
|
-
# MongoDB to use a specific index for the query.
|
|
224
|
+
# MongoDB to use a specific index for the query.
|
|
227
225
|
# @option opts :limit [ Integer ] Max number of docs to count.
|
|
228
226
|
# @option opts :max_time_ms [ Integer ] The maximum amount of time to allow the
|
|
229
227
|
# command to run. This option is deprecated, use
|
|
@@ -231,7 +229,7 @@ module Mongo
|
|
|
231
229
|
# @option opts [ Hash ] :read The read preference options.
|
|
232
230
|
# @option opts [ Hash ] :collation The collation to use.
|
|
233
231
|
# @option opts [ Mongo::Session ] :session The session to use for the operation.
|
|
234
|
-
# @option
|
|
232
|
+
# @option opts [ Object ] :comment A user-provided
|
|
235
233
|
# comment to attach to this command.
|
|
236
234
|
# @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
|
|
237
235
|
# Must be a non-negative integer. An explicit value of 0 means infinite.
|
|
@@ -243,16 +241,17 @@ module Mongo
|
|
|
243
241
|
# @since 2.6.0
|
|
244
242
|
def count_documents(opts = {})
|
|
245
243
|
opts = @options.merge(opts) unless Mongo.broken_view_options
|
|
246
|
-
pipeline = [
|
|
247
|
-
pipeline << {
|
|
248
|
-
pipeline << {
|
|
249
|
-
pipeline << {
|
|
244
|
+
pipeline = [ { '$match': filter } ]
|
|
245
|
+
pipeline << { '$skip': opts[:skip] } if opts[:skip]
|
|
246
|
+
pipeline << { '$limit': opts[:limit] } if opts[:limit]
|
|
247
|
+
pipeline << { '$group': { _id: 1, n: { '$sum': 1 } } }
|
|
250
248
|
|
|
251
249
|
opts = opts.slice(:hint, :max_time_ms, :read, :collation, :session, :comment, :timeout_ms)
|
|
252
250
|
opts[:collation] ||= collation
|
|
253
251
|
|
|
254
252
|
first = aggregate(pipeline, opts).first
|
|
255
253
|
return 0 unless first
|
|
254
|
+
|
|
256
255
|
first['n'].to_i
|
|
257
256
|
end
|
|
258
257
|
|
|
@@ -278,7 +277,7 @@ module Mongo
|
|
|
278
277
|
# @since 2.6.0
|
|
279
278
|
def estimated_document_count(opts = {})
|
|
280
279
|
unless view.filter.empty?
|
|
281
|
-
raise ArgumentError,
|
|
280
|
+
raise ArgumentError, 'Cannot call estimated_document_count when querying with a filter'
|
|
282
281
|
end
|
|
283
282
|
|
|
284
283
|
%i[limit skip].each do |opt|
|
|
@@ -299,31 +298,27 @@ module Mongo
|
|
|
299
298
|
)
|
|
300
299
|
cmd = { count: collection.name }
|
|
301
300
|
cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
|
|
302
|
-
if read_concern
|
|
303
|
-
cmd[:readConcern] = Options::Mapper.transform_values_to_strings(read_concern)
|
|
304
|
-
end
|
|
301
|
+
cmd[:readConcern] = Options::Mapper.transform_values_to_strings(read_concern) if read_concern
|
|
305
302
|
operation = Operation::Count.new(
|
|
306
303
|
selector: cmd,
|
|
307
304
|
db_name: database.name,
|
|
308
305
|
read: read_pref,
|
|
309
306
|
session: session,
|
|
310
|
-
comment: opts[:comment]
|
|
307
|
+
comment: opts[:comment]
|
|
311
308
|
)
|
|
312
309
|
tracer.trace_operation(operation, context, op_name: 'estimatedDocumentCount') do
|
|
313
310
|
read_with_retry(session, selector, context) do |server|
|
|
314
311
|
result = operation.execute(server, context: context)
|
|
315
312
|
result.n.to_i
|
|
316
313
|
end
|
|
317
|
-
rescue Error::OperationFailure::Family =>
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
raise
|
|
326
|
-
end
|
|
314
|
+
rescue Error::OperationFailure::Family => e
|
|
315
|
+
raise unless e.code == 26
|
|
316
|
+
|
|
317
|
+
# NamespaceNotFound
|
|
318
|
+
# This should only happen with the aggregation pipeline path
|
|
319
|
+
# (server 4.9+). Previous servers should return 0 for nonexistent
|
|
320
|
+
# collections.
|
|
321
|
+
0
|
|
327
322
|
end
|
|
328
323
|
end
|
|
329
324
|
end
|
|
@@ -347,17 +342,17 @@ module Mongo
|
|
|
347
342
|
#
|
|
348
343
|
# @since 2.0.0
|
|
349
344
|
def distinct(field_name, opts = {})
|
|
350
|
-
if field_name.nil?
|
|
351
|
-
|
|
352
|
-
end
|
|
345
|
+
raise ArgumentError, 'Field name for distinct operation must be not nil' if field_name.nil?
|
|
346
|
+
|
|
353
347
|
opts = @options.merge(opts) unless Mongo.broken_view_options
|
|
354
|
-
cmd = { :
|
|
355
|
-
:
|
|
356
|
-
:
|
|
348
|
+
cmd = { distinct: collection.name,
|
|
349
|
+
key: field_name.to_s,
|
|
350
|
+
query: filter, }
|
|
357
351
|
cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
|
|
358
352
|
if read_concern
|
|
359
353
|
cmd[:readConcern] = Options::Mapper.transform_values_to_strings(
|
|
360
|
-
read_concern
|
|
354
|
+
read_concern
|
|
355
|
+
)
|
|
361
356
|
end
|
|
362
357
|
Mongo::Lint.validate_underscore_read_preference(opts[:read])
|
|
363
358
|
read_pref = opts[:read] || read_preference
|
|
@@ -371,13 +366,13 @@ module Mongo
|
|
|
371
366
|
operation = Operation::Distinct.new(
|
|
372
367
|
selector: cmd,
|
|
373
368
|
db_name: database.name,
|
|
374
|
-
options: {:
|
|
369
|
+
options: { limit: -1 },
|
|
375
370
|
read: read_pref,
|
|
376
371
|
session: session,
|
|
377
372
|
comment: opts[:comment],
|
|
378
373
|
# For some reason collation was historically accepted as a
|
|
379
374
|
# string key. Note that this isn't documented as valid usage.
|
|
380
|
-
collation: opts[:collation] || opts['collation'] || collation
|
|
375
|
+
collation: opts[:collation] || opts['collation'] || collation
|
|
381
376
|
)
|
|
382
377
|
tracer.trace_operation(operation, context) do
|
|
383
378
|
read_with_retry(session, selector, context) do |server|
|
|
@@ -524,6 +519,7 @@ module Mongo
|
|
|
524
519
|
# @since 2.0.0
|
|
525
520
|
def read(value = nil)
|
|
526
521
|
return read_preference if value.nil?
|
|
522
|
+
|
|
527
523
|
configure(:read, value)
|
|
528
524
|
end
|
|
529
525
|
|
|
@@ -555,7 +551,7 @@ module Mongo
|
|
|
555
551
|
def show_disk_loc(value = nil)
|
|
556
552
|
configure(:show_disk_loc, value)
|
|
557
553
|
end
|
|
558
|
-
alias
|
|
554
|
+
alias show_record_id show_disk_loc
|
|
559
555
|
|
|
560
556
|
# The number of docs to skip before returning results.
|
|
561
557
|
#
|
|
@@ -697,24 +693,22 @@ module Mongo
|
|
|
697
693
|
# collection read preference. If we are not in transaction we
|
|
698
694
|
# look at collection read preference which defaults to client.
|
|
699
695
|
rp = if options[:read]
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
696
|
+
options[:read]
|
|
697
|
+
elsif options[:session] && options[:session].in_transaction?
|
|
698
|
+
options[:session].txn_read_preference || collection.client.read_preference
|
|
699
|
+
else
|
|
700
|
+
collection.read_preference
|
|
701
|
+
end
|
|
706
702
|
Lint.validate_underscore_read_preference(rp)
|
|
707
703
|
rp
|
|
708
704
|
end
|
|
709
705
|
end
|
|
710
706
|
|
|
711
707
|
def parallel_scan(cursor_count, options = {})
|
|
712
|
-
if options[:session]
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
session = nil
|
|
717
|
-
end
|
|
708
|
+
session = if options[:session]
|
|
709
|
+
# The session would be overwritten by the one in +options+ later.
|
|
710
|
+
client.get_session(@options)
|
|
711
|
+
end
|
|
718
712
|
server = server_selector.select_server(cluster, nil, session)
|
|
719
713
|
spec = {
|
|
720
714
|
coll_name: collection.name,
|
|
@@ -736,14 +730,13 @@ module Mongo
|
|
|
736
730
|
db_name: database.name,
|
|
737
731
|
session: session,
|
|
738
732
|
batch_size: batch_size,
|
|
739
|
-
to_return: 0,
|
|
740
733
|
# max_time_ms is not being passed here, I assume intentionally?
|
|
741
734
|
}
|
|
742
735
|
op = Operation::GetMore.new(spec)
|
|
743
736
|
context = Operation::Context.new(
|
|
744
737
|
client: client,
|
|
745
738
|
session: session,
|
|
746
|
-
connection_global_id: result.connection_global_id
|
|
739
|
+
connection_global_id: result.connection_global_id
|
|
747
740
|
)
|
|
748
741
|
result = if server.load_balancer?
|
|
749
742
|
# Connection will be checked in when cursor is drained.
|
|
@@ -764,10 +757,10 @@ module Mongo
|
|
|
764
757
|
|
|
765
758
|
def server_selector
|
|
766
759
|
@server_selector ||= if options[:session] && options[:session].in_transaction?
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
760
|
+
ServerSelector.get(read_preference || client.server_selector)
|
|
761
|
+
else
|
|
762
|
+
ServerSelector.get(read_preference || collection.server_selector)
|
|
763
|
+
end
|
|
771
764
|
end
|
|
772
765
|
|
|
773
766
|
def validate_doc!(doc)
|