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-2022 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -21,7 +20,7 @@ module Mongo
|
|
|
21
20
|
#
|
|
22
21
|
# @api private
|
|
23
22
|
module Helpers
|
|
24
|
-
# Executes drop operation and
|
|
23
|
+
# Executes drop operation and ignores NamespaceNotFound error.
|
|
25
24
|
#
|
|
26
25
|
# @param [ Operation::Drop ] operation Drop operation to be executed.
|
|
27
26
|
# @param [ Session ] session Session to be use for execution.
|
|
@@ -30,13 +29,11 @@ module Mongo
|
|
|
30
29
|
# @return [ Result ] The result of the execution.
|
|
31
30
|
def do_drop(operation, session, context)
|
|
32
31
|
operation.execute(next_primary(nil, session), context: context)
|
|
33
|
-
rescue Error::OperationFailure::Family =>
|
|
32
|
+
rescue Error::OperationFailure::Family => e
|
|
34
33
|
# NamespaceNotFound
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
raise
|
|
39
|
-
end
|
|
34
|
+
raise unless e.code == 26 || (e.code.nil? && e.message =~ /ns not found/)
|
|
35
|
+
|
|
36
|
+
false
|
|
40
37
|
end
|
|
41
38
|
end
|
|
42
39
|
end
|
|
@@ -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/collection/view/aggregation/behavior'
|
|
|
20
19
|
module Mongo
|
|
21
20
|
class Collection
|
|
22
21
|
class View
|
|
23
|
-
|
|
24
22
|
# Provides behavior around an aggregation pipeline on a collection view.
|
|
25
23
|
#
|
|
26
24
|
# @since 2.0.0
|
|
@@ -71,9 +69,7 @@ module Mongo
|
|
|
71
69
|
def initialize(view, pipeline, options = {})
|
|
72
70
|
perform_setup(view, options) do
|
|
73
71
|
@pipeline = pipeline.dup
|
|
74
|
-
unless Mongo.broken_view_aggregate || view.filter.empty?
|
|
75
|
-
@pipeline.unshift(:$match => view.filter)
|
|
76
|
-
end
|
|
72
|
+
@pipeline.unshift(:$match => view.filter) unless Mongo.broken_view_aggregate || view.filter.empty?
|
|
77
73
|
end
|
|
78
74
|
end
|
|
79
75
|
|
|
@@ -104,20 +100,19 @@ module Mongo
|
|
|
104
100
|
def effective_read_preference(connection)
|
|
105
101
|
return unless view.read_preference
|
|
106
102
|
return view.read_preference unless write?
|
|
107
|
-
return view.read_preference unless [
|
|
103
|
+
return view.read_preference unless %i[secondary secondary_preferred].include?(view.read_preference[:mode])
|
|
108
104
|
|
|
109
|
-
primary_read_preference = {mode: :primary}
|
|
105
|
+
primary_read_preference = { mode: :primary }
|
|
110
106
|
description = connection.description
|
|
111
107
|
if description.primary?
|
|
112
|
-
log_warn(
|
|
108
|
+
log_warn('Routing the Aggregation operation to the primary server')
|
|
113
109
|
primary_read_preference
|
|
114
110
|
elsif description.mongos? && !description.features.merge_out_on_secondary_enabled?
|
|
115
|
-
log_warn(
|
|
111
|
+
log_warn('Routing the Aggregation operation to the primary server')
|
|
116
112
|
primary_read_preference
|
|
117
113
|
else
|
|
118
114
|
view.read_preference
|
|
119
115
|
end
|
|
120
|
-
|
|
121
116
|
end
|
|
122
117
|
|
|
123
118
|
def send_initial_query(server, context, operation: nil)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2015-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -19,7 +18,6 @@ module Mongo
|
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
20
|
module Builder
|
|
22
|
-
|
|
23
21
|
# Builds an aggregation command specification from the view and options.
|
|
24
22
|
#
|
|
25
23
|
# @since 2.2.0
|
|
@@ -40,7 +38,7 @@ module Mongo
|
|
|
40
38
|
# This is intentional; max_await_time_ms is an alias for maxTimeMS
|
|
41
39
|
# used on getMore commands for change streams.
|
|
42
40
|
max_await_time_ms: 'maxTimeMS',
|
|
43
|
-
max_time_ms: 'maxTimeMS'
|
|
41
|
+
max_time_ms: 'maxTimeMS'
|
|
44
42
|
).freeze
|
|
45
43
|
|
|
46
44
|
def_delegators :@view, :collection, :database, :read, :write_concern
|
|
@@ -83,9 +81,7 @@ module Mongo
|
|
|
83
81
|
session: @options[:session],
|
|
84
82
|
collation: @options[:collation],
|
|
85
83
|
}
|
|
86
|
-
if write?
|
|
87
|
-
spec.update(write_concern: write_concern)
|
|
88
|
-
end
|
|
84
|
+
spec.update(write_concern: write_concern) if write?
|
|
89
85
|
spec
|
|
90
86
|
end
|
|
91
87
|
|
|
@@ -94,7 +90,7 @@ module Mongo
|
|
|
94
90
|
def write?
|
|
95
91
|
pipeline.any? do |operator|
|
|
96
92
|
operator[:$out] || operator['$out'] ||
|
|
97
|
-
|
|
93
|
+
operator[:$merge] || operator['$merge']
|
|
98
94
|
end
|
|
99
95
|
end
|
|
100
96
|
|
|
@@ -111,7 +107,8 @@ module Mongo
|
|
|
111
107
|
command[:pipeline] = pipeline
|
|
112
108
|
if read_concern = view.read_concern
|
|
113
109
|
command[:readConcern] = Options::Mapper.transform_values_to_strings(
|
|
114
|
-
read_concern
|
|
110
|
+
read_concern
|
|
111
|
+
)
|
|
115
112
|
end
|
|
116
113
|
command[:cursor] = batch_size_doc
|
|
117
114
|
command.merge!(Options::Mapper.transform_documents(options, MAPPINGS))
|
|
@@ -123,7 +120,7 @@ module Mongo
|
|
|
123
120
|
if value == 0 && write?
|
|
124
121
|
{}
|
|
125
122
|
elsif value
|
|
126
|
-
{ :
|
|
123
|
+
{ batchSize: value }
|
|
127
124
|
else
|
|
128
125
|
{}
|
|
129
126
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2015-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -19,7 +18,6 @@ module Mongo
|
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
20
|
module Builder
|
|
22
|
-
|
|
23
21
|
# Builds a map/reduce specification from the view and options.
|
|
24
22
|
#
|
|
25
23
|
# @since 2.2.0
|
|
@@ -36,7 +34,7 @@ module Mongo
|
|
|
36
34
|
scope: 'scope',
|
|
37
35
|
verbose: 'verbose',
|
|
38
36
|
bypass_document_validation: 'bypassDocumentValidation',
|
|
39
|
-
collation: 'collation'
|
|
37
|
+
collation: 'collation'
|
|
40
38
|
).freeze
|
|
41
39
|
|
|
42
40
|
def_delegators :@view, :collection, :database, :filter, :read, :write_concern
|
|
@@ -94,24 +92,25 @@ module Mongo
|
|
|
94
92
|
private
|
|
95
93
|
|
|
96
94
|
def write?(spec)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
return unless out = spec[:selector][:out]
|
|
96
|
+
|
|
97
|
+
out.is_a?(String) ||
|
|
98
|
+
(out.respond_to?(:keys) && out.keys.first.to_s.downcase != View::MapReduce::INLINE)
|
|
101
99
|
end
|
|
102
100
|
|
|
103
101
|
def map_reduce_command
|
|
104
102
|
command = BSON::Document.new(
|
|
105
|
-
:
|
|
106
|
-
:
|
|
107
|
-
:
|
|
108
|
-
:
|
|
109
|
-
:
|
|
103
|
+
mapReduce: collection.name,
|
|
104
|
+
map: map,
|
|
105
|
+
reduce: reduce,
|
|
106
|
+
query: filter,
|
|
107
|
+
out: { inline: 1 }
|
|
110
108
|
)
|
|
111
109
|
# Shouldn't this use self.read ?
|
|
112
110
|
if collection.read_concern
|
|
113
111
|
command[:readConcern] = Options::Mapper.transform_values_to_strings(
|
|
114
|
-
collection.read_concern
|
|
112
|
+
collection.read_concern
|
|
113
|
+
)
|
|
115
114
|
end
|
|
116
115
|
command.update(view_options)
|
|
117
116
|
command.update(options.slice(:collation))
|
|
@@ -121,16 +120,18 @@ module Mongo
|
|
|
121
120
|
# Ideally it should be removed here, however due to Mongoid 7
|
|
122
121
|
# using this method and requiring :read to be returned from it,
|
|
123
122
|
# we cannot do this just yet - see RUBY-2932.
|
|
124
|
-
#command.delete(:read)
|
|
123
|
+
# command.delete(:read)
|
|
125
124
|
|
|
126
125
|
command.merge!(Options::Mapper.transform_documents(options, MAPPINGS))
|
|
127
126
|
command
|
|
128
127
|
end
|
|
129
128
|
|
|
130
129
|
def view_options
|
|
131
|
-
@view_options ||=
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
@view_options ||= begin
|
|
131
|
+
opts = view.options.dup
|
|
132
|
+
opts.delete(:session)
|
|
133
|
+
opts
|
|
134
|
+
end
|
|
134
135
|
end
|
|
135
136
|
end
|
|
136
137
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2017-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -19,22 +18,18 @@ module Mongo
|
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
20
|
class ChangeStream < Aggregation
|
|
22
|
-
|
|
23
21
|
# Behavior around resuming a change stream.
|
|
24
22
|
#
|
|
25
23
|
# @since 2.5.0
|
|
26
24
|
module Retryable
|
|
27
|
-
|
|
28
25
|
private
|
|
29
26
|
|
|
30
27
|
def read_with_one_retry
|
|
31
28
|
yield
|
|
32
29
|
rescue Mongo::Error => e
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
raise(e)
|
|
37
|
-
end
|
|
30
|
+
raise(e) unless e.change_stream_resumable?
|
|
31
|
+
|
|
32
|
+
yield
|
|
38
33
|
end
|
|
39
34
|
end
|
|
40
35
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2017-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -21,20 +20,11 @@ require 'mongo/collection/view/change_stream/retryable'
|
|
|
21
20
|
module Mongo
|
|
22
21
|
class Collection
|
|
23
22
|
class View
|
|
24
|
-
|
|
25
23
|
# Provides behavior around a `$changeStream` pipeline stage in the
|
|
26
24
|
# aggregation framework. Specifying this stage allows users to request
|
|
27
25
|
# that notifications are sent for all changes to a particular collection
|
|
28
26
|
# or database.
|
|
29
27
|
#
|
|
30
|
-
# @note Only available in server versions 3.6 and higher.
|
|
31
|
-
# @note ChangeStreams do not work properly with JRuby because of the
|
|
32
|
-
# issue documented here: https://github.com/jruby/jruby/issues/4212.
|
|
33
|
-
# Namely, JRuby eagerly evaluates #next on an Enumerator in a background
|
|
34
|
-
# green thread, therefore calling #next on the change stream will cause
|
|
35
|
-
# getMores to be called in a loop in the background.
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
28
|
# @since 2.5.0
|
|
39
29
|
class ChangeStream
|
|
40
30
|
include Aggregation::Behavior
|
|
@@ -43,7 +33,7 @@ module Mongo
|
|
|
43
33
|
# @return [ String ] The fullDocument option default value.
|
|
44
34
|
#
|
|
45
35
|
# @since 2.5.0
|
|
46
|
-
FULL_DOCUMENT_DEFAULT = 'default'
|
|
36
|
+
FULL_DOCUMENT_DEFAULT = 'default'
|
|
47
37
|
|
|
48
38
|
# @return [ Symbol ] Used to indicate that the change stream should listen for changes on
|
|
49
39
|
# the entire database rather than just the collection.
|
|
@@ -66,6 +56,16 @@ module Mongo
|
|
|
66
56
|
# @api private
|
|
67
57
|
attr_reader :cursor
|
|
68
58
|
|
|
59
|
+
# Refreshes the CSOT timeout for the next iteration. Delegates to the
|
|
60
|
+
# underlying cursor's refresh_timeout! method so that each call to
|
|
61
|
+
# try_next starts with a fresh timeout deadline, as required by the
|
|
62
|
+
# CSOT spec for tailable awaitData cursors.
|
|
63
|
+
#
|
|
64
|
+
# @api private
|
|
65
|
+
def refresh_timeout!
|
|
66
|
+
@cursor&.refresh_timeout!
|
|
67
|
+
end
|
|
68
|
+
|
|
69
69
|
# Initialize the change stream for the provided collection view, pipeline
|
|
70
70
|
# and options.
|
|
71
71
|
#
|
|
@@ -114,7 +114,7 @@ module Mongo
|
|
|
114
114
|
# @option options [ BSON::Timestamp ] :start_at_operation_time Only
|
|
115
115
|
# return changes that occurred at or after the specified timestamp. Any
|
|
116
116
|
# command run against the server will return a cluster time that can
|
|
117
|
-
# be used here.
|
|
117
|
+
# be used here.
|
|
118
118
|
# @option options [ Bson::Document, Hash ] :start_after Similar to :resume_after, this
|
|
119
119
|
# option takes a resume token and starts a new change stream returning the first
|
|
120
120
|
# notification after the token. This will allow users to watch collections that have been
|
|
@@ -168,12 +168,13 @@ module Mongo
|
|
|
168
168
|
# @yieldparam [ BSON::Document ] Each change stream document.
|
|
169
169
|
def each
|
|
170
170
|
raise StopIteration.new if closed?
|
|
171
|
+
|
|
171
172
|
loop do
|
|
172
173
|
document = try_next
|
|
173
174
|
yield document if document
|
|
174
175
|
end
|
|
175
176
|
rescue StopIteration
|
|
176
|
-
|
|
177
|
+
self
|
|
177
178
|
end
|
|
178
179
|
|
|
179
180
|
# Return one document from the change stream, if one is available.
|
|
@@ -218,9 +219,8 @@ module Mongo
|
|
|
218
219
|
|
|
219
220
|
# We need to verify each doc has an _id, so we
|
|
220
221
|
# have a resume token to work with
|
|
221
|
-
if doc && doc['_id'].nil?
|
|
222
|
-
|
|
223
|
-
end
|
|
222
|
+
raise Error::MissingResumeToken if doc && doc['_id'].nil?
|
|
223
|
+
|
|
224
224
|
doc
|
|
225
225
|
end
|
|
226
226
|
|
|
@@ -252,14 +252,14 @@ module Mongo
|
|
|
252
252
|
#
|
|
253
253
|
# @since 2.5.0
|
|
254
254
|
def close(opts = {})
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
@cursor = nil
|
|
255
|
+
return if closed?
|
|
256
|
+
|
|
257
|
+
begin
|
|
258
|
+
@cursor.close(opts)
|
|
259
|
+
rescue Error::OperationFailure::Family, Error::SocketError, Error::SocketTimeoutError, Error::MissingConnection
|
|
260
|
+
# ignore
|
|
262
261
|
end
|
|
262
|
+
@cursor = nil
|
|
263
263
|
end
|
|
264
264
|
|
|
265
265
|
# Is the change stream closed?
|
|
@@ -340,61 +340,66 @@ module Mongo
|
|
|
340
340
|
def create_cursor!(timeout_ms = nil)
|
|
341
341
|
# clear the cache because we may get a newer or an older server
|
|
342
342
|
# (rolling upgrades)
|
|
343
|
-
@start_at_operation_time_supported = nil
|
|
344
|
-
|
|
345
343
|
session = client.get_session(@options)
|
|
346
|
-
context = Operation::Context.new(client: client, session: session, view: self,
|
|
344
|
+
context = Operation::Context.new(client: client, session: session, view: self,
|
|
345
|
+
operation_timeouts: timeout_ms ? { operation_timeout_ms: timeout_ms } : operation_timeouts)
|
|
347
346
|
|
|
348
347
|
start_at_operation_time = nil
|
|
349
|
-
start_at_operation_time_supported = nil
|
|
350
348
|
|
|
351
349
|
@cursor = read_with_retry_cursor(session, server_selector, self, context: context) do |server|
|
|
352
|
-
server.
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
if server.load_balancer?
|
|
351
|
+
# In load balanced topology, manually check out a connection
|
|
352
|
+
# so it remains checked out and pinned to the cursor.
|
|
353
|
+
connection = server.pool.check_out(context: context)
|
|
355
354
|
result = send_initial_query(connection, context)
|
|
356
355
|
|
|
357
|
-
if doc = result.replies.first && result.replies.first.documents.first
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
# for consistency set it to nil here as well.
|
|
363
|
-
# NB: since this block may be executed more than once, each
|
|
364
|
-
# execution must write to start_at_operation_time either way.
|
|
365
|
-
start_at_operation_time = nil
|
|
366
|
-
end
|
|
356
|
+
start_at_operation_time = if doc = result.replies.first && result.replies.first.documents.first
|
|
357
|
+
doc['operationTime']
|
|
358
|
+
else
|
|
359
|
+
nil
|
|
360
|
+
end
|
|
367
361
|
result
|
|
362
|
+
else
|
|
363
|
+
server.with_connection do |connection|
|
|
364
|
+
result = send_initial_query(connection, context)
|
|
365
|
+
|
|
366
|
+
start_at_operation_time = if doc = result.replies.first && result.replies.first.documents.first
|
|
367
|
+
doc['operationTime']
|
|
368
|
+
else
|
|
369
|
+
# The above may set @start_at_operation_time to nil
|
|
370
|
+
# if it was not in the document for some reason,
|
|
371
|
+
# for consistency set it to nil here as well.
|
|
372
|
+
# NB: since this block may be executed more than once, each
|
|
373
|
+
# execution must write to start_at_operation_time either way.
|
|
374
|
+
nil
|
|
375
|
+
end
|
|
376
|
+
result
|
|
377
|
+
end
|
|
368
378
|
end
|
|
369
379
|
end
|
|
370
380
|
|
|
371
381
|
@start_at_operation_time = start_at_operation_time
|
|
372
|
-
@start_at_operation_time_supported = start_at_operation_time_supported
|
|
373
382
|
end
|
|
374
383
|
|
|
375
384
|
def pipeline
|
|
376
|
-
[{ '$changeStream' => change_doc }] + @change_stream_filters
|
|
385
|
+
[ { '$changeStream' => change_doc } ] + @change_stream_filters
|
|
377
386
|
end
|
|
378
387
|
|
|
379
388
|
def aggregate_spec(session, read_preference)
|
|
380
|
-
super
|
|
389
|
+
super.tap do |spec|
|
|
381
390
|
spec[:selector][:aggregate] = 1 unless for_collection?
|
|
382
391
|
end
|
|
383
392
|
end
|
|
384
393
|
|
|
385
394
|
def change_doc
|
|
386
395
|
{}.tap do |doc|
|
|
387
|
-
if @options[:full_document]
|
|
388
|
-
doc[:fullDocument] = @options[:full_document]
|
|
389
|
-
end
|
|
396
|
+
doc[:fullDocument] = @options[:full_document] if @options[:full_document]
|
|
390
397
|
|
|
391
398
|
if @options[:full_document_before_change]
|
|
392
399
|
doc[:fullDocumentBeforeChange] = @options[:full_document_before_change]
|
|
393
400
|
end
|
|
394
401
|
|
|
395
|
-
if @options.key?(:show_expanded_events)
|
|
396
|
-
doc[:showExpandedEvents] = @options[:show_expanded_events]
|
|
397
|
-
end
|
|
402
|
+
doc[:showExpandedEvents] = @options[:show_expanded_events] if @options.key?(:show_expanded_events)
|
|
398
403
|
|
|
399
404
|
if resuming?
|
|
400
405
|
# We have a resume token once we retrieved any documents.
|
|
@@ -405,12 +410,7 @@ module Mongo
|
|
|
405
410
|
# Spec says we need to remove both startAtOperationTime and startAfter if
|
|
406
411
|
# either was passed in by user, thus we won't forward them
|
|
407
412
|
doc[:resumeAfter] = resume_token
|
|
408
|
-
elsif @
|
|
409
|
-
# It is crucial to check @start_at_operation_time_supported
|
|
410
|
-
# here - we may have switched to an older server that
|
|
411
|
-
# does not support operation times and therefore shouldn't
|
|
412
|
-
# try to send one to it!
|
|
413
|
-
#
|
|
413
|
+
elsif @start_at_operation_time
|
|
414
414
|
# @start_at_operation_time is already a BSON::Timestamp
|
|
415
415
|
doc[:startAtOperationTime] = @start_at_operation_time
|
|
416
416
|
else
|
|
@@ -426,7 +426,8 @@ module Mongo
|
|
|
426
426
|
|
|
427
427
|
if options[:start_at_operation_time]
|
|
428
428
|
doc[:startAtOperationTime] = time_to_bson_timestamp(
|
|
429
|
-
options[:start_at_operation_time]
|
|
429
|
+
options[:start_at_operation_time]
|
|
430
|
+
)
|
|
430
431
|
end
|
|
431
432
|
end
|
|
432
433
|
|
|
@@ -438,14 +439,14 @@ module Mongo
|
|
|
438
439
|
initial_query_op(context.session, view.read_preference)
|
|
439
440
|
.execute_with_connection(
|
|
440
441
|
connection,
|
|
441
|
-
context: context
|
|
442
|
+
context: context
|
|
442
443
|
)
|
|
443
444
|
end
|
|
444
445
|
|
|
445
446
|
def time_to_bson_timestamp(time)
|
|
446
447
|
if time.is_a?(Time)
|
|
447
448
|
seconds = time.to_f
|
|
448
|
-
BSON::Timestamp.new(seconds.to_i, ((seconds - seconds.to_i) *
|
|
449
|
+
BSON::Timestamp.new(seconds.to_i, ((seconds - seconds.to_i) * 1_000_000).to_i)
|
|
449
450
|
elsif time.is_a?(BSON::Timestamp)
|
|
450
451
|
time
|
|
451
452
|
else
|
|
@@ -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,38 +17,34 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
|
-
|
|
22
20
|
# Defines explain related behavior for collection view.
|
|
23
21
|
#
|
|
24
22
|
# @since 2.0.0
|
|
25
23
|
module Explainable
|
|
26
|
-
|
|
27
24
|
# The query planner verbosity constant.
|
|
28
25
|
#
|
|
29
26
|
# @since 2.2.0
|
|
30
|
-
QUERY_PLANNER = 'queryPlanner'
|
|
27
|
+
QUERY_PLANNER = 'queryPlanner'
|
|
31
28
|
|
|
32
29
|
# The execution stats verbosity constant.
|
|
33
30
|
#
|
|
34
31
|
# @since 2.2.0
|
|
35
|
-
EXECUTION_STATS = 'executionStats'
|
|
32
|
+
EXECUTION_STATS = 'executionStats'
|
|
36
33
|
|
|
37
34
|
# The all plans execution verbosity constant.
|
|
38
35
|
#
|
|
39
36
|
# @since 2.2.0
|
|
40
|
-
ALL_PLANS_EXECUTION = 'allPlansExecution'
|
|
37
|
+
ALL_PLANS_EXECUTION = 'allPlansExecution'
|
|
41
38
|
|
|
42
39
|
# Get the query plan for the query.
|
|
43
40
|
#
|
|
44
41
|
# @example Get the query plan for the query with execution statistics.
|
|
45
42
|
# view.explain(verbosity: :execution_stats)
|
|
46
43
|
#
|
|
47
|
-
# @option opts [ true | false ] :verbose The level of detail
|
|
48
|
-
# to return for MongoDB 2.6 servers.
|
|
49
44
|
# @option opts [ String | Symbol ] :verbosity The type of information
|
|
50
|
-
# to return
|
|
51
|
-
#
|
|
52
|
-
#
|
|
45
|
+
# to return. If the value is a symbol, it will be stringified and
|
|
46
|
+
# converted from underscore style to camel case style
|
|
47
|
+
# (e.g. :query_planner => "queryPlanner").
|
|
53
48
|
#
|
|
54
49
|
# @return [ Hash ] A single document with the query plan.
|
|
55
50
|
#
|
|
@@ -66,18 +61,14 @@ module Mongo
|
|
|
66
61
|
!!options[:explain]
|
|
67
62
|
end
|
|
68
63
|
|
|
69
|
-
# @option opts [ true | false ] :verbose The level of detail
|
|
70
|
-
# to return for MongoDB 2.6 servers.
|
|
71
64
|
# @option opts [ String | Symbol ] :verbosity The type of information
|
|
72
|
-
# to return
|
|
73
|
-
#
|
|
74
|
-
#
|
|
65
|
+
# to return. If the value is a symbol, it will be stringified and
|
|
66
|
+
# converted from underscore style to camel case style
|
|
67
|
+
# (e.g. :query_planner => "queryPlanner").
|
|
75
68
|
def explain_options(**opts)
|
|
76
69
|
explain_limit = limit || 0
|
|
77
|
-
#
|
|
78
|
-
|
|
79
|
-
opts[:verbosity] = Utils.camelize(opts[:verbosity])
|
|
80
|
-
end
|
|
70
|
+
# NOTE: opts will never be nil here.
|
|
71
|
+
opts[:verbosity] = Utils.camelize(opts[:verbosity]) if opts[:verbosity].is_a?(Symbol)
|
|
81
72
|
{ limit: -explain_limit.abs, explain: opts }
|
|
82
73
|
end
|
|
83
74
|
end
|
|
@@ -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 behavior around views being configurable and immutable.
|
|
23
21
|
#
|
|
24
22
|
# @since 2.0.0
|
|
25
23
|
module Immutable
|
|
26
|
-
|
|
27
24
|
# @return [ Hash ] options The additional query options.
|
|
28
25
|
attr_reader :options
|
|
29
26
|
|
|
@@ -31,6 +28,7 @@ module Mongo
|
|
|
31
28
|
|
|
32
29
|
def configure(field, value)
|
|
33
30
|
return options[field] if value.nil?
|
|
31
|
+
|
|
34
32
|
new(options.merge(field => value))
|
|
35
33
|
end
|
|
36
34
|
end
|