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
|
#
|
|
@@ -18,16 +17,14 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
class Collection
|
|
20
19
|
class View
|
|
21
|
-
|
|
22
20
|
# Defines write related behavior for collection view.
|
|
23
21
|
#
|
|
24
22
|
# @since 2.0.0
|
|
25
23
|
module Writable
|
|
26
|
-
|
|
27
24
|
# The array filters field constant.
|
|
28
25
|
#
|
|
29
26
|
# @since 2.5.0
|
|
30
|
-
ARRAY_FILTERS = 'array_filters'
|
|
27
|
+
ARRAY_FILTERS = 'array_filters'
|
|
31
28
|
|
|
32
29
|
# Finds a single document in the database via findAndModify and deletes
|
|
33
30
|
# it, returning the original document.
|
|
@@ -64,10 +61,10 @@ module Mongo
|
|
|
64
61
|
def find_one_and_delete(opts = {})
|
|
65
62
|
with_session(opts) do |session|
|
|
66
63
|
write_concern = if opts[:write_concern]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
WriteConcern.get(opts[:write_concern])
|
|
65
|
+
else
|
|
66
|
+
write_concern_with_session(session)
|
|
67
|
+
end
|
|
71
68
|
|
|
72
69
|
QueryCache.clear_namespace(collection.namespace)
|
|
73
70
|
|
|
@@ -101,7 +98,7 @@ module Mongo
|
|
|
101
98
|
db_name: database.name,
|
|
102
99
|
write_concern: write_concern,
|
|
103
100
|
session: session,
|
|
104
|
-
txn_num: txn_num
|
|
101
|
+
txn_num: txn_num
|
|
105
102
|
).execute_with_connection(connection, context: context)
|
|
106
103
|
end
|
|
107
104
|
end.first&.fetch('value', nil)
|
|
@@ -182,10 +179,10 @@ module Mongo
|
|
|
182
179
|
def find_one_and_update(document, opts = {})
|
|
183
180
|
value = with_session(opts) do |session|
|
|
184
181
|
write_concern = if opts[:write_concern]
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
182
|
+
WriteConcern.get(opts[:write_concern])
|
|
183
|
+
else
|
|
184
|
+
write_concern_with_session(session)
|
|
185
|
+
end
|
|
189
186
|
|
|
190
187
|
QueryCache.clear_namespace(collection.namespace)
|
|
191
188
|
|
|
@@ -215,7 +212,7 @@ module Mongo
|
|
|
215
212
|
selector: cmd,
|
|
216
213
|
db_name: database.name,
|
|
217
214
|
write_concern: write_concern,
|
|
218
|
-
session: session
|
|
215
|
+
session: session
|
|
219
216
|
)
|
|
220
217
|
value = tracer.trace_operation(operation, context, op_name: 'findOneAndUpdate') do
|
|
221
218
|
write_with_retry(write_concern, context: context) do |connection, txn_num, context|
|
|
@@ -223,6 +220,7 @@ module Mongo
|
|
|
223
220
|
if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
|
|
224
221
|
raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
|
|
225
222
|
end
|
|
223
|
+
|
|
226
224
|
operation.txn_num = txn_num
|
|
227
225
|
operation.execute_with_connection(connection, context: context)
|
|
228
226
|
end
|
|
@@ -259,10 +257,10 @@ module Mongo
|
|
|
259
257
|
def delete_many(opts = {})
|
|
260
258
|
with_session(opts) do |session|
|
|
261
259
|
write_concern = if opts[:write_concern]
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
260
|
+
WriteConcern.get(opts[:write_concern])
|
|
261
|
+
else
|
|
262
|
+
write_concern_with_session(session)
|
|
263
|
+
end
|
|
266
264
|
|
|
267
265
|
QueryCache.clear_namespace(collection.namespace)
|
|
268
266
|
|
|
@@ -285,14 +283,15 @@ module Mongo
|
|
|
285
283
|
bypass_document_validation: !!opts[:bypass_document_validation],
|
|
286
284
|
session: session,
|
|
287
285
|
let: opts[:let],
|
|
288
|
-
comment: opts[:comment]
|
|
286
|
+
comment: opts[:comment]
|
|
289
287
|
)
|
|
290
288
|
tracer.trace_operation(operation, context, op_name: 'deleteMany') do
|
|
291
|
-
nro_write_with_retry(write_concern, context: context) do |connection,
|
|
289
|
+
nro_write_with_retry(write_concern, context: context) do |connection, _txn_num, context|
|
|
292
290
|
gte_4_4 = connection.server.description.server_version_gte?('4.4')
|
|
293
291
|
if !gte_4_4 && opts[:hint] && write_concern && !write_concern.acknowledged?
|
|
294
292
|
raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
|
|
295
293
|
end
|
|
294
|
+
|
|
296
295
|
operation.execute_with_connection(connection, context: context)
|
|
297
296
|
end
|
|
298
297
|
end
|
|
@@ -327,10 +326,10 @@ module Mongo
|
|
|
327
326
|
def delete_one(opts = {})
|
|
328
327
|
with_session(opts) do |session|
|
|
329
328
|
write_concern = if opts[:write_concern]
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
329
|
+
WriteConcern.get(opts[:write_concern])
|
|
330
|
+
else
|
|
331
|
+
write_concern_with_session(session)
|
|
332
|
+
end
|
|
334
333
|
|
|
335
334
|
QueryCache.clear_namespace(collection.namespace)
|
|
336
335
|
|
|
@@ -361,7 +360,7 @@ module Mongo
|
|
|
361
360
|
session: session,
|
|
362
361
|
txn_num: txn_num,
|
|
363
362
|
let: opts[:let],
|
|
364
|
-
comment: opts[:comment]
|
|
363
|
+
comment: opts[:comment]
|
|
365
364
|
).execute_with_connection(connection, context: context)
|
|
366
365
|
end
|
|
367
366
|
end
|
|
@@ -405,10 +404,10 @@ module Mongo
|
|
|
405
404
|
def replace_one(replacement, opts = {})
|
|
406
405
|
with_session(opts) do |session|
|
|
407
406
|
write_concern = if opts[:write_concern]
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
407
|
+
WriteConcern.get(opts[:write_concern])
|
|
408
|
+
else
|
|
409
|
+
write_concern_with_session(session)
|
|
410
|
+
end
|
|
412
411
|
validate_replacement_documents!(replacement)
|
|
413
412
|
|
|
414
413
|
QueryCache.clear_namespace(collection.namespace)
|
|
@@ -421,9 +420,7 @@ module Mongo
|
|
|
421
420
|
collation: opts[:collation] || opts['collation'] || collation,
|
|
422
421
|
sort: opts[:sort] || opts['sort'],
|
|
423
422
|
}.compact
|
|
424
|
-
if opts[:upsert]
|
|
425
|
-
update_doc['upsert'] = true
|
|
426
|
-
end
|
|
423
|
+
update_doc['upsert'] = true if opts[:upsert]
|
|
427
424
|
|
|
428
425
|
context = Operation::Context.new(
|
|
429
426
|
client: client,
|
|
@@ -445,7 +442,7 @@ module Mongo
|
|
|
445
442
|
session: session,
|
|
446
443
|
txn_num: txn_num,
|
|
447
444
|
let: opts[:let],
|
|
448
|
-
comment: opts[:comment]
|
|
445
|
+
comment: opts[:comment]
|
|
449
446
|
).execute_with_connection(connection, context: context)
|
|
450
447
|
end
|
|
451
448
|
end
|
|
@@ -486,10 +483,10 @@ module Mongo
|
|
|
486
483
|
def update_many(spec, opts = {})
|
|
487
484
|
with_session(opts) do |session|
|
|
488
485
|
write_concern = if opts[:write_concern]
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
486
|
+
WriteConcern.get(opts[:write_concern])
|
|
487
|
+
else
|
|
488
|
+
write_concern_with_session(session)
|
|
489
|
+
end
|
|
493
490
|
validate_update_documents!(spec)
|
|
494
491
|
|
|
495
492
|
QueryCache.clear_namespace(collection.namespace)
|
|
@@ -502,16 +499,14 @@ module Mongo
|
|
|
502
499
|
hint: opts[:hint],
|
|
503
500
|
collation: opts[:collation] || opts['collation'] || collation,
|
|
504
501
|
}.compact
|
|
505
|
-
if opts[:upsert]
|
|
506
|
-
update_doc['upsert'] = true
|
|
507
|
-
end
|
|
502
|
+
update_doc['upsert'] = true if opts[:upsert]
|
|
508
503
|
|
|
509
504
|
context = Operation::Context.new(
|
|
510
505
|
client: client,
|
|
511
506
|
session: session,
|
|
512
507
|
operation_timeouts: operation_timeouts(opts)
|
|
513
508
|
)
|
|
514
|
-
nro_write_with_retry(write_concern, context: context) do |connection,
|
|
509
|
+
nro_write_with_retry(write_concern, context: context) do |connection, _txn_num, context|
|
|
515
510
|
gte_4_2 = connection.server.description.server_version_gte?('4.2')
|
|
516
511
|
if !gte_4_2 && opts[:hint] && write_concern && !write_concern.acknowledged?
|
|
517
512
|
raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
|
|
@@ -525,7 +520,7 @@ module Mongo
|
|
|
525
520
|
bypass_document_validation: !!opts[:bypass_document_validation],
|
|
526
521
|
session: session,
|
|
527
522
|
let: opts[:let],
|
|
528
|
-
comment: opts[:comment]
|
|
523
|
+
comment: opts[:comment]
|
|
529
524
|
).execute_with_connection(connection, context: context)
|
|
530
525
|
end
|
|
531
526
|
end
|
|
@@ -571,10 +566,10 @@ module Mongo
|
|
|
571
566
|
def update_one(spec, opts = {})
|
|
572
567
|
with_session(opts) do |session|
|
|
573
568
|
write_concern = if opts[:write_concern]
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
569
|
+
WriteConcern.get(opts[:write_concern])
|
|
570
|
+
else
|
|
571
|
+
write_concern_with_session(session)
|
|
572
|
+
end
|
|
578
573
|
validate_update_documents!(spec)
|
|
579
574
|
|
|
580
575
|
QueryCache.clear_namespace(collection.namespace)
|
|
@@ -587,9 +582,7 @@ module Mongo
|
|
|
587
582
|
collation: opts[:collation] || opts['collation'] || collation,
|
|
588
583
|
sort: opts[:sort] || opts['sort'],
|
|
589
584
|
}.compact
|
|
590
|
-
if opts[:upsert]
|
|
591
|
-
update_doc['upsert'] = true
|
|
592
|
-
end
|
|
585
|
+
update_doc['upsert'] = true if opts[:upsert]
|
|
593
586
|
|
|
594
587
|
context = Operation::Context.new(
|
|
595
588
|
client: client,
|
|
@@ -604,7 +597,7 @@ module Mongo
|
|
|
604
597
|
bypass_document_validation: !!opts[:bypass_document_validation],
|
|
605
598
|
session: session,
|
|
606
599
|
let: opts[:let],
|
|
607
|
-
comment: opts[:comment]
|
|
600
|
+
comment: opts[:comment]
|
|
608
601
|
)
|
|
609
602
|
tracer.trace_operation(operation, context) do
|
|
610
603
|
write_with_retry(write_concern, context: context) do |connection, txn_num, context|
|
|
@@ -612,6 +605,7 @@ module Mongo
|
|
|
612
605
|
if !gte_4_2 && opts[:hint] && write_concern && !write_concern.acknowledged?
|
|
613
606
|
raise Error::UnsupportedOption.hint_error(unacknowledged_write: true)
|
|
614
607
|
end
|
|
608
|
+
|
|
615
609
|
operation.txn_num = txn_num
|
|
616
610
|
operation.execute_with_connection(connection, context: context)
|
|
617
611
|
end
|
|
@@ -630,17 +624,12 @@ module Mongo
|
|
|
630
624
|
# @raise [ Error::InvalidUpdateDocument ] if the first key in the
|
|
631
625
|
# document does not start with a $.
|
|
632
626
|
def validate_update_documents!(spec)
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
Error::InvalidUpdateDocument.warn(Logger.logger, key)
|
|
640
|
-
end
|
|
641
|
-
end
|
|
642
|
-
end
|
|
643
|
-
end
|
|
627
|
+
return unless update = spec.is_a?(Array) ? spec&.first : spec
|
|
628
|
+
return unless key = update.keys&.first
|
|
629
|
+
return if key.to_s.start_with?('$')
|
|
630
|
+
raise Error::InvalidUpdateDocument.new(key: key) if Mongo.validate_update_replace
|
|
631
|
+
|
|
632
|
+
Error::InvalidUpdateDocument.warn(Logger.logger, key)
|
|
644
633
|
end
|
|
645
634
|
|
|
646
635
|
# Check the replacement documents to make sure they don't have atomic
|
|
@@ -652,17 +641,12 @@ module Mongo
|
|
|
652
641
|
# @raise [ Error::InvalidUpdateDocument ] if the first key in the
|
|
653
642
|
# document does not start with a $.
|
|
654
643
|
def validate_replacement_documents!(spec)
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
Error::InvalidReplacementDocument.warn(Logger.logger, key)
|
|
662
|
-
end
|
|
663
|
-
end
|
|
664
|
-
end
|
|
665
|
-
end
|
|
644
|
+
return unless replace = spec.is_a?(Array) ? spec&.first : spec
|
|
645
|
+
return unless key = replace.keys&.first
|
|
646
|
+
return unless key.to_s.start_with?('$')
|
|
647
|
+
raise Error::InvalidReplacementDocument.new(key: key) if Mongo.validate_update_replace
|
|
648
|
+
|
|
649
|
+
Error::InvalidReplacementDocument.warn(Logger.logger, key)
|
|
666
650
|
end
|
|
667
651
|
end
|
|
668
652
|
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
|
#
|
|
@@ -27,7 +26,6 @@ require 'mongo/collection/view/writable'
|
|
|
27
26
|
|
|
28
27
|
module Mongo
|
|
29
28
|
class Collection
|
|
30
|
-
|
|
31
29
|
# Representation of a query and options producing a result set of documents.
|
|
32
30
|
#
|
|
33
31
|
# A +View+ can be modified using helpers. Helpers can be chained,
|
|
@@ -74,7 +72,7 @@ module Mongo
|
|
|
74
72
|
|
|
75
73
|
def_delegators :client, :tracer
|
|
76
74
|
|
|
77
|
-
alias
|
|
75
|
+
alias selector filter
|
|
78
76
|
|
|
79
77
|
# @return [ Integer | nil | The timeout_ms value that was passed as an
|
|
80
78
|
# option to the view.
|
|
@@ -93,11 +91,12 @@ module Mongo
|
|
|
93
91
|
# @since 2.0.0
|
|
94
92
|
def ==(other)
|
|
95
93
|
return false unless other.is_a?(View)
|
|
94
|
+
|
|
96
95
|
collection == other.collection &&
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
filter == other.filter &&
|
|
97
|
+
options == other.options
|
|
99
98
|
end
|
|
100
|
-
|
|
99
|
+
alias eql? ==
|
|
101
100
|
|
|
102
101
|
# A hash value for the +View+ composed of the collection namespace,
|
|
103
102
|
# hash of the options and hash of the filter.
|
|
@@ -208,7 +207,7 @@ module Mongo
|
|
|
208
207
|
# @since 2.0.0
|
|
209
208
|
def inspect
|
|
210
209
|
"#<Mongo::Collection::View:0x#{object_id} namespace='#{collection.namespace}'" +
|
|
211
|
-
|
|
210
|
+
" @filter=#{filter} @options=#{options}>"
|
|
212
211
|
end
|
|
213
212
|
|
|
214
213
|
# Get the write concern on this +View+.
|
|
@@ -250,7 +249,9 @@ module Mongo
|
|
|
250
249
|
View.new(collection, filter, options)
|
|
251
250
|
end
|
|
252
251
|
|
|
253
|
-
def view
|
|
252
|
+
def view
|
|
253
|
+
self
|
|
254
|
+
end
|
|
254
255
|
|
|
255
256
|
def with_session(opts = {}, &block)
|
|
256
257
|
client.with_session(@options.merge(opts), &block)
|
data/lib/mongo/collection.rb
CHANGED
|
@@ -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
|
#
|
|
@@ -21,7 +20,6 @@ require 'mongo/collection/helpers'
|
|
|
21
20
|
require 'mongo/collection/queryable_encryption'
|
|
22
21
|
|
|
23
22
|
module Mongo
|
|
24
|
-
|
|
25
23
|
# Represents a collection in the database and operations that can directly be
|
|
26
24
|
# applied to one.
|
|
27
25
|
#
|
|
@@ -35,12 +33,12 @@ module Mongo
|
|
|
35
33
|
# The capped option.
|
|
36
34
|
#
|
|
37
35
|
# @since 2.1.0
|
|
38
|
-
CAPPED = 'capped'
|
|
36
|
+
CAPPED = 'capped'
|
|
39
37
|
|
|
40
38
|
# The ns field constant.
|
|
41
39
|
#
|
|
42
40
|
# @since 2.1.0
|
|
43
|
-
NS = 'ns'
|
|
41
|
+
NS = 'ns'
|
|
44
42
|
|
|
45
43
|
# @return [ Mongo::Database ] The database the collection resides in.
|
|
46
44
|
attr_reader :database
|
|
@@ -62,19 +60,19 @@ module Mongo
|
|
|
62
60
|
# Options that can be updated on a new Collection instance via the #with method.
|
|
63
61
|
#
|
|
64
62
|
# @since 2.1.0
|
|
65
|
-
CHANGEABLE_OPTIONS = [
|
|
63
|
+
CHANGEABLE_OPTIONS = %i[read read_concern write write_concern].freeze
|
|
66
64
|
|
|
67
65
|
# Options map to transform create collection options.
|
|
68
66
|
#
|
|
69
67
|
# @api private
|
|
70
68
|
CREATE_COLLECTION_OPTIONS = {
|
|
71
|
-
:
|
|
72
|
-
:
|
|
73
|
-
:
|
|
74
|
-
:
|
|
75
|
-
:
|
|
76
|
-
:
|
|
77
|
-
:
|
|
69
|
+
time_series: :timeseries,
|
|
70
|
+
expire_after: :expireAfterSeconds,
|
|
71
|
+
clustered_index: :clusteredIndex,
|
|
72
|
+
change_stream_pre_and_post_images: :changeStreamPreAndPostImages,
|
|
73
|
+
encrypted_fields: :encryptedFields,
|
|
74
|
+
validator: :validator,
|
|
75
|
+
view_on: :viewOn
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
# Check if a collection is equal to another object. Will check the name and
|
|
@@ -90,6 +88,7 @@ module Mongo
|
|
|
90
88
|
# @since 2.0.0
|
|
91
89
|
def ==(other)
|
|
92
90
|
return false unless other.is_a?(Collection)
|
|
91
|
+
|
|
93
92
|
name == other.name && database == other.database && options == other.options
|
|
94
93
|
end
|
|
95
94
|
|
|
@@ -166,17 +165,17 @@ module Mongo
|
|
|
166
165
|
if options[:write] && options[:write_concern] && options[:write] != options[:write_concern]
|
|
167
166
|
raise ArgumentError, "If :write and :write_concern are both given, they must be identical: #{options.inspect}"
|
|
168
167
|
end
|
|
168
|
+
|
|
169
169
|
@database = database
|
|
170
170
|
@name = name.to_s.freeze
|
|
171
171
|
@options = options.dup
|
|
172
172
|
@timeout_ms = options.delete(:timeout_ms)
|
|
173
|
-
|
|
174
|
-
if @options[:write_concern].is_a?(WriteConcern::Base)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
end
|
|
179
|
-
=end
|
|
173
|
+
# WriteConcern object support
|
|
174
|
+
# if @options[:write_concern].is_a?(WriteConcern::Base)
|
|
175
|
+
# # Cache the instance so that we do not needlessly reconstruct it.
|
|
176
|
+
# @write_concern = @options[:write_concern]
|
|
177
|
+
# @options[:write_concern] = @write_concern.options
|
|
178
|
+
# end
|
|
180
179
|
@options.freeze
|
|
181
180
|
end
|
|
182
181
|
|
|
@@ -238,7 +237,8 @@ module Mongo
|
|
|
238
237
|
# @since 2.0.0
|
|
239
238
|
def write_concern
|
|
240
239
|
@write_concern ||= WriteConcern.get(
|
|
241
|
-
options[:write_concern] || options[:write] || database.write_concern
|
|
240
|
+
options[:write_concern] || options[:write] || database.write_concern
|
|
241
|
+
)
|
|
242
242
|
end
|
|
243
243
|
|
|
244
244
|
# Get the write concern to use for an operation on this collection,
|
|
@@ -254,12 +254,10 @@ module Mongo
|
|
|
254
254
|
# @api private
|
|
255
255
|
def write_concern_with_session(session)
|
|
256
256
|
wc = write_concern
|
|
257
|
-
if session && session.in_transaction?
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return WriteConcern.get(opts)
|
|
262
|
-
end
|
|
257
|
+
if session && session.in_transaction? && wc && !wc.acknowledged?
|
|
258
|
+
opts = wc.options.dup
|
|
259
|
+
opts.delete(:w)
|
|
260
|
+
return WriteConcern.get(opts)
|
|
263
261
|
end
|
|
264
262
|
wc
|
|
265
263
|
end
|
|
@@ -303,12 +301,8 @@ module Mongo
|
|
|
303
301
|
raise Error::UnchangeableCollectionOption.new(k) unless CHANGEABLE_OPTIONS.include?(k)
|
|
304
302
|
end
|
|
305
303
|
options = @options.dup
|
|
306
|
-
if options[:write] && new_options[:write_concern]
|
|
307
|
-
|
|
308
|
-
end
|
|
309
|
-
if options[:write_concern] && new_options[:write]
|
|
310
|
-
options.delete(:write_concern)
|
|
311
|
-
end
|
|
304
|
+
options.delete(:write) if options[:write] && new_options[:write_concern]
|
|
305
|
+
options.delete(:write_concern) if options[:write_concern] && new_options[:write]
|
|
312
306
|
Collection.new(database, name, options.update(new_options))
|
|
313
307
|
end
|
|
314
308
|
|
|
@@ -322,8 +316,8 @@ module Mongo
|
|
|
322
316
|
# @since 2.0.0
|
|
323
317
|
def capped?
|
|
324
318
|
database.list_collections(filter: { name: name })
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
.first
|
|
320
|
+
&.dig('options', CAPPED) || false
|
|
327
321
|
end
|
|
328
322
|
|
|
329
323
|
# Force the collection to be created in the database.
|
|
@@ -389,24 +383,22 @@ module Mongo
|
|
|
389
383
|
# serialization.
|
|
390
384
|
# TODO put the list of read options in a class-level constant when
|
|
391
385
|
# we figure out what the full set of them is.
|
|
392
|
-
options = Hash[self.options.merge(opts).reject do |key,
|
|
393
|
-
%w
|
|
386
|
+
options = Hash[self.options.merge(opts).reject do |key, _value|
|
|
387
|
+
%w[read read_preference read_concern session].include?(key.to_s)
|
|
394
388
|
end]
|
|
395
389
|
# Converting Ruby options to server style.
|
|
396
390
|
CREATE_COLLECTION_OPTIONS.each do |ruby_key, server_key|
|
|
397
|
-
if options.key?(ruby_key)
|
|
398
|
-
options[server_key] = options.delete(ruby_key)
|
|
399
|
-
end
|
|
391
|
+
options[server_key] = options.delete(ruby_key) if options.key?(ruby_key)
|
|
400
392
|
end
|
|
401
|
-
operation = { :
|
|
393
|
+
operation = { create: name }.merge(options)
|
|
402
394
|
operation.delete(:write)
|
|
403
395
|
operation.delete(:write_concern)
|
|
404
396
|
client.send(:with_session, opts) do |session|
|
|
405
397
|
write_concern = if opts[:write_concern]
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
398
|
+
WriteConcern.get(opts[:write_concern])
|
|
399
|
+
else
|
|
400
|
+
self.write_concern
|
|
401
|
+
end
|
|
410
402
|
|
|
411
403
|
context = Operation::Context.new(
|
|
412
404
|
client: client,
|
|
@@ -420,7 +412,7 @@ module Mongo
|
|
|
420
412
|
# Note that these are collection options, collation isn't
|
|
421
413
|
# taken from options passed to the create method.
|
|
422
414
|
collation: options[:collation] || options['collation'],
|
|
423
|
-
validator: options[:validator]
|
|
415
|
+
validator: options[:validator]
|
|
424
416
|
)
|
|
425
417
|
tracer.trace_operation(operation, context, op_name: 'createCollection') do
|
|
426
418
|
maybe_create_qe_collections(opts[:encrypted_fields], client, session) do |encrypted_fields|
|
|
@@ -470,11 +462,11 @@ module Mongo
|
|
|
470
462
|
temp_write_concern
|
|
471
463
|
end
|
|
472
464
|
operation = Operation::Drop.new({
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
465
|
+
selector: { drop: name },
|
|
466
|
+
db_name: database.name,
|
|
467
|
+
write_concern: write_concern,
|
|
468
|
+
session: session,
|
|
469
|
+
})
|
|
478
470
|
tracer.trace_operation(operation, context, op_name: 'dropCollection') do
|
|
479
471
|
maybe_drop_emm_collections(opts[:encrypted_fields], client, session) do
|
|
480
472
|
do_drop(operation, session, context)
|
|
@@ -576,10 +568,8 @@ module Mongo
|
|
|
576
568
|
View.new(self, {}, options).aggregate(pipeline, options)
|
|
577
569
|
end
|
|
578
570
|
|
|
579
|
-
#
|
|
580
|
-
#
|
|
581
|
-
# to request that notifications are sent for all changes to a particular
|
|
582
|
-
# collection.
|
|
571
|
+
# Allows users to request that notifications are sent for all changes
|
|
572
|
+
# to a particular collection.
|
|
583
573
|
#
|
|
584
574
|
# @example Get change notifications for a given collection.
|
|
585
575
|
# collection.watch([{ '$match' => { operationType: { '$in' => ['insert', 'replace'] } } }])
|
|
@@ -627,7 +617,6 @@ module Mongo
|
|
|
627
617
|
# @option options [ BSON::Timestamp ] :start_at_operation_time Only return
|
|
628
618
|
# changes that occurred at or after the specified timestamp. Any command run
|
|
629
619
|
# against the server will return a cluster time that can be used here.
|
|
630
|
-
# Only recognized by server versions 4.0+.
|
|
631
620
|
# @option options [ Object ] :comment A user-provided
|
|
632
621
|
# comment to attach to this command.
|
|
633
622
|
# @option options [ Boolean ] :show_expanded_events Enables the server to
|
|
@@ -686,7 +675,7 @@ module Mongo
|
|
|
686
675
|
#
|
|
687
676
|
# @deprecated Use #count_documents or estimated_document_count instead. However, note that the
|
|
688
677
|
# following operators will need to be substituted when switching to #count_documents:
|
|
689
|
-
# * $where should be replaced with $expr
|
|
678
|
+
# * $where should be replaced with $expr
|
|
690
679
|
# * $near should be replaced with $geoWithin with $center
|
|
691
680
|
# * $nearSphere should be replaced with $geoWithin with $centerSphere
|
|
692
681
|
def count(filter = nil, options = {})
|
|
@@ -706,7 +695,7 @@ module Mongo
|
|
|
706
695
|
#
|
|
707
696
|
# @option options :skip [ Integer ] The number of documents to skip.
|
|
708
697
|
# @option options :hint [ Hash ] Override default index selection and force
|
|
709
|
-
# MongoDB to use a specific index for the query.
|
|
698
|
+
# MongoDB to use a specific index for the query.
|
|
710
699
|
# @option options :limit [ Integer ] Max number of docs to count.
|
|
711
700
|
# @option options :max_time_ms [ Integer ] The maximum amount of time to allow the
|
|
712
701
|
# command to run.
|
|
@@ -858,31 +847,29 @@ module Mongo
|
|
|
858
847
|
|
|
859
848
|
client.with_session(opts) do |session|
|
|
860
849
|
write_concern = if opts[:write_concern]
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
850
|
+
WriteConcern.get(opts[:write_concern])
|
|
851
|
+
else
|
|
852
|
+
write_concern_with_session(session)
|
|
853
|
+
end
|
|
865
854
|
|
|
866
|
-
if document.nil?
|
|
867
|
-
raise ArgumentError, "Document to be inserted cannot be nil"
|
|
868
|
-
end
|
|
855
|
+
raise ArgumentError, 'Document to be inserted cannot be nil' if document.nil?
|
|
869
856
|
|
|
870
857
|
context = Operation::Context.new(
|
|
871
858
|
client: client,
|
|
872
859
|
session: session,
|
|
873
860
|
operation_timeouts: operation_timeouts(opts)
|
|
874
|
-
|
|
861
|
+
)
|
|
875
862
|
operation = Operation::Insert.new(
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
863
|
+
documents: [ document ],
|
|
864
|
+
db_name: database.name,
|
|
865
|
+
coll_name: name,
|
|
866
|
+
write_concern: write_concern,
|
|
867
|
+
bypass_document_validation: !!opts[:bypass_document_validation],
|
|
868
|
+
options: opts,
|
|
869
|
+
id_generator: client.options[:id_generator],
|
|
870
|
+
session: session,
|
|
871
|
+
comment: opts[:comment]
|
|
872
|
+
)
|
|
886
873
|
tracer.trace_operation(operation, context) do
|
|
887
874
|
write_with_retry(write_concern, context: context) do |connection, txn_num, context|
|
|
888
875
|
operation.txn_num = txn_num
|
|
@@ -920,7 +907,7 @@ module Mongo
|
|
|
920
907
|
def insert_many(documents, options = {})
|
|
921
908
|
QueryCache.clear_namespace(namespace)
|
|
922
909
|
|
|
923
|
-
inserts = documents.map{ |doc| { :
|
|
910
|
+
inserts = documents.map { |doc| { insert_one: doc } }
|
|
924
911
|
bulk_write(inserts, options)
|
|
925
912
|
end
|
|
926
913
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -32,6 +31,7 @@ module Mongo
|
|
|
32
31
|
def wait(timeout = nil)
|
|
33
32
|
raise_unless_locked!
|
|
34
33
|
return false if timeout && timeout < 0
|
|
34
|
+
|
|
35
35
|
@cv.wait(@lock, timeout)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -50,9 +50,9 @@ module Mongo
|
|
|
50
50
|
private
|
|
51
51
|
|
|
52
52
|
def raise_unless_locked!
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
return if @lock.owned?
|
|
54
|
+
|
|
55
|
+
raise ArgumentError, 'the lock must be owned when calling this method'
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|