mongo 2.15.0 → 2.16.1
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
- checksums.yaml.gz.sig +0 -0
- data/README.md +1 -1
- data/lib/mongo/bulk_write.rb +2 -2
- data/lib/mongo/client.rb +45 -5
- data/lib/mongo/cluster/periodic_executor.rb +4 -3
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +76 -43
- data/lib/mongo/cluster/sdam_flow.rb +9 -3
- data/lib/mongo/cluster/topology/base.rb +13 -9
- data/lib/mongo/cluster/topology/load_balanced.rb +102 -0
- data/lib/mongo/cluster/topology.rb +28 -8
- data/lib/mongo/cluster.rb +136 -51
- data/lib/mongo/collection/view/aggregation.rb +5 -10
- data/lib/mongo/collection/view/builder/aggregation.rb +6 -5
- data/lib/mongo/collection/view/builder/map_reduce.rb +12 -49
- data/lib/mongo/collection/view/builder.rb +0 -4
- data/lib/mongo/collection/view/iterable.rb +58 -24
- data/lib/mongo/collection/view/map_reduce.rb +39 -15
- data/lib/mongo/collection/view/readable.rb +60 -51
- data/lib/mongo/collection/view/writable.rb +178 -175
- data/lib/mongo/collection/view.rb +15 -21
- data/lib/mongo/collection.rb +13 -13
- data/lib/mongo/cursor/kill_spec.rb +38 -0
- data/lib/mongo/cursor.rb +72 -31
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/error/bad_load_balancer_target.rb +26 -0
- data/lib/mongo/error/missing_service_id.rb +26 -0
- data/lib/mongo/error/no_service_connection_available.rb +49 -0
- data/lib/mongo/error/notable.rb +7 -0
- data/lib/mongo/error.rb +3 -0
- data/lib/mongo/grid/fs_bucket.rb +21 -2
- data/lib/mongo/id.rb +7 -5
- data/lib/mongo/index/view.rb +22 -41
- data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +7 -4
- data/lib/mongo/monitoring/event/command_failed.rb +1 -1
- data/lib/mongo/monitoring/event/command_started.rb +2 -0
- data/lib/mongo/monitoring/publishable.rb +2 -2
- data/lib/mongo/operation/aggregate/command.rb +8 -0
- data/lib/mongo/operation/context.rb +19 -1
- data/lib/mongo/operation/count/command.rb +6 -0
- data/lib/mongo/operation/count/op_msg.rb +6 -0
- data/lib/mongo/operation/create/command.rb +7 -1
- data/lib/mongo/operation/create/op_msg.rb +7 -0
- data/lib/mongo/operation/create_index/command.rb +17 -1
- data/lib/mongo/operation/create_index/op_msg.rb +17 -4
- data/lib/mongo/operation/delete/command.rb +6 -3
- data/lib/mongo/operation/delete/legacy.rb +9 -2
- data/lib/mongo/operation/delete/op_msg.rb +8 -1
- data/lib/mongo/operation/distinct/command.rb +6 -0
- data/lib/mongo/operation/distinct/op_msg.rb +7 -0
- data/lib/mongo/operation/explain/command.rb +13 -1
- data/lib/mongo/operation/explain/legacy.rb +12 -5
- data/lib/mongo/operation/explain/op_msg.rb +9 -1
- data/lib/mongo/operation/find/builder/command.rb +110 -0
- data/lib/mongo/{collection/view → operation/find}/builder/flags.rb +10 -14
- data/lib/mongo/operation/find/builder/legacy.rb +123 -0
- data/lib/mongo/{collection/view → operation/find}/builder/modifiers.rb +31 -25
- data/lib/mongo/{cursor → operation/find}/builder.rb +4 -4
- data/lib/mongo/operation/find/command.rb +9 -0
- data/lib/mongo/operation/find/legacy.rb +10 -1
- data/lib/mongo/operation/find/op_msg.rb +12 -0
- data/lib/mongo/operation/find.rb +1 -0
- data/lib/mongo/operation/get_more/command.rb +1 -0
- data/lib/mongo/operation/get_more/command_builder.rb +38 -0
- data/lib/mongo/operation/get_more/op_msg.rb +1 -0
- data/lib/mongo/operation/get_more.rb +1 -0
- data/lib/mongo/operation/kill_cursors/command.rb +8 -0
- data/lib/mongo/operation/kill_cursors/command_builder.rb +35 -0
- data/lib/mongo/operation/kill_cursors/legacy.rb +2 -1
- data/lib/mongo/operation/kill_cursors/op_msg.rb +10 -0
- data/lib/mongo/operation/kill_cursors.rb +1 -0
- data/lib/mongo/operation/map_reduce/command.rb +8 -0
- data/lib/mongo/operation/map_reduce/op_msg.rb +1 -1
- data/lib/mongo/operation/shared/executable.rb +15 -1
- data/lib/mongo/operation/shared/polymorphic_operation.rb +1 -1
- data/lib/mongo/operation/shared/read_preference_supported.rb +3 -1
- data/lib/mongo/operation/shared/response_handling.rb +1 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +12 -12
- data/lib/mongo/operation/shared/specifiable.rb +11 -29
- data/lib/mongo/operation/shared/validatable.rb +87 -0
- data/lib/mongo/operation/shared/write.rb +1 -1
- data/lib/mongo/operation/update/command.rb +6 -3
- data/lib/mongo/operation/update/legacy.rb +19 -11
- data/lib/mongo/operation/update/op_msg.rb +7 -4
- data/lib/mongo/operation/write_command/command.rb +51 -0
- data/lib/mongo/operation/write_command/op_msg.rb +43 -0
- data/lib/mongo/operation/write_command.rb +32 -0
- data/lib/mongo/operation.rb +10 -0
- data/lib/mongo/protocol/query.rb +35 -18
- data/lib/mongo/server/connection.rb +25 -3
- data/lib/mongo/server/connection_base.rb +12 -1
- data/lib/mongo/server/connection_common.rb +38 -1
- data/lib/mongo/server/connection_pool/generation_manager.rb +71 -0
- data/lib/mongo/server/connection_pool.rb +100 -27
- data/lib/mongo/server/description/features.rb +17 -16
- data/lib/mongo/server/description/load_balancer.rb +33 -0
- data/lib/mongo/server/description.rb +85 -6
- data/lib/mongo/server/monitor/connection.rb +5 -6
- data/lib/mongo/server/monitor.rb +2 -1
- data/lib/mongo/server/pending_connection.rb +47 -31
- data/lib/mongo/server/push_monitor.rb +10 -1
- data/lib/mongo/server.rb +73 -26
- data/lib/mongo/server_selector/base.rb +5 -1
- data/lib/mongo/session/session_pool.rb +11 -0
- data/lib/mongo/session.rb +21 -1
- data/lib/mongo/socket/ocsp_verifier.rb +6 -37
- data/lib/mongo/uri/options_mapper.rb +1 -0
- data/lib/mongo/uri/srv_protocol.rb +6 -8
- data/lib/mongo/uri.rb +18 -0
- data/lib/mongo/utils.rb +0 -7
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/integration/auth_spec.rb +31 -1
- data/spec/integration/awaited_ismaster_spec.rb +1 -1
- data/spec/integration/bulk_write_spec.rb +1 -1
- data/spec/integration/change_stream_spec.rb +3 -3
- data/spec/integration/client_construction_spec.rb +54 -0
- data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +1 -1
- data/spec/integration/client_side_encryption/auto_encryption_command_monitoring_spec.rb +1 -1
- data/spec/integration/client_side_encryption/bson_size_limit_spec.rb +1 -1
- data/spec/integration/client_side_encryption/data_key_spec.rb +1 -1
- data/spec/integration/client_spec.rb +2 -0
- data/spec/integration/command_monitoring_spec.rb +1 -1
- data/spec/integration/command_spec.rb +1 -1
- data/spec/integration/connection_spec.rb +52 -35
- data/spec/integration/crud_spec.rb +174 -1
- data/spec/integration/cursor_pinning_spec.rb +121 -0
- data/spec/integration/cursor_reaping_spec.rb +8 -4
- data/spec/integration/fork_reconnect_spec.rb +1 -5
- data/spec/integration/get_more_spec.rb +1 -1
- data/spec/integration/heartbeat_events_spec.rb +1 -1
- data/spec/integration/map_reduce_spec.rb +77 -0
- data/spec/integration/query_cache_spec.rb +47 -2
- data/spec/integration/query_cache_transactions_spec.rb +1 -1
- data/spec/integration/read_concern_spec.rb +1 -1
- data/spec/integration/read_preference_spec.rb +1 -1
- data/spec/integration/reconnect_spec.rb +30 -12
- data/spec/integration/retryable_errors_spec.rb +1 -1
- data/spec/integration/retryable_writes/retryable_writes_36_and_older_spec.rb +1 -1
- data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -1
- data/spec/integration/sdam_error_handling_spec.rb +5 -3
- data/spec/integration/sdam_events_spec.rb +35 -19
- data/spec/integration/sdam_prose_spec.rb +1 -1
- data/spec/integration/server_monitor_spec.rb +1 -0
- data/spec/integration/server_selector_spec.rb +22 -5
- data/spec/integration/server_spec.rb +2 -0
- data/spec/integration/srv_monitoring_spec.rb +1 -1
- data/spec/integration/step_down_spec.rb +1 -1
- data/spec/integration/transaction_pinning_spec.rb +120 -0
- data/spec/integration/versioned_api_examples_spec.rb +45 -0
- data/spec/integration/x509_auth_spec.rb +1 -1
- data/spec/lite_spec_helper.rb +1 -2
- data/spec/mongo/address/unix_spec.rb +1 -0
- data/spec/mongo/auth/cr_spec.rb +2 -3
- data/spec/mongo/auth/ldap_spec.rb +2 -3
- data/spec/mongo/auth/scram_spec.rb +2 -3
- data/spec/mongo/auth/user/view_spec.rb +1 -1
- data/spec/mongo/auth/x509_spec.rb +2 -3
- data/spec/mongo/bulk_write_spec.rb +3 -3
- data/spec/mongo/client_construction_spec.rb +259 -28
- data/spec/mongo/client_spec.rb +6 -4
- data/spec/mongo/cluster/cursor_reaper_spec.rb +36 -21
- data/spec/mongo/cluster/periodic_executor_spec.rb +3 -1
- data/spec/mongo/cluster_spec.rb +44 -3
- data/spec/mongo/collection/view/aggregation_spec.rb +1 -1
- data/spec/mongo/collection/view/builder/find_command_spec.rb +4 -0
- data/spec/mongo/collection/view/builder/op_query_spec.rb +4 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +1 -1
- data/spec/mongo/collection_crud_spec.rb +7 -2
- data/spec/mongo/collection_ddl_spec.rb +1 -1
- data/spec/mongo/collection_spec.rb +1 -1
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +4 -0
- data/spec/mongo/cursor/builder/op_get_more_spec.rb +4 -0
- data/spec/mongo/cursor_spec.rb +15 -5
- data/spec/mongo/database_spec.rb +15 -15
- data/spec/mongo/error/operation_failure_heavy_spec.rb +1 -1
- data/spec/mongo/grid/fs_bucket_spec.rb +18 -12
- data/spec/mongo/grid/stream/write_spec.rb +3 -9
- data/spec/mongo/grid/stream_spec.rb +1 -1
- data/spec/mongo/index/view_spec.rb +2 -2
- data/spec/mongo/operation/delete/op_msg_spec.rb +1 -1
- data/spec/mongo/{collection/view → operation/find}/builder/flags_spec.rb +2 -2
- data/spec/mongo/{collection/view → operation/find}/builder/modifiers_spec.rb +2 -2
- data/spec/mongo/operation/find/legacy_spec.rb +1 -0
- data/spec/mongo/operation/insert/bulk_spec.rb +1 -1
- data/spec/mongo/operation/insert/op_msg_spec.rb +1 -1
- data/spec/mongo/operation/kill_cursors_spec.rb +4 -1
- data/spec/mongo/operation/read_preference_legacy_spec.rb +4 -0
- data/spec/mongo/operation/read_preference_op_msg_spec.rb +2 -0
- data/spec/mongo/operation/update/bulk_spec.rb +1 -1
- data/spec/mongo/operation/update/op_msg_spec.rb +1 -1
- data/spec/mongo/query_cache_spec.rb +6 -2
- data/spec/mongo/server/connection_common_spec.rb +62 -11
- data/spec/mongo/server/connection_pool_spec.rb +73 -7
- data/spec/mongo/server/connection_spec.rb +138 -43
- data/spec/mongo/server/description_spec.rb +1 -1
- data/spec/mongo/server/monitor/connection_spec.rb +22 -0
- data/spec/mongo/server/monitor_spec.rb +4 -3
- data/spec/mongo/server/push_monitor_spec.rb +101 -0
- data/spec/mongo/session/session_pool_spec.rb +42 -10
- data/spec/mongo/session_transaction_spec.rb +15 -30
- data/spec/mongo/socket/unix_spec.rb +1 -0
- data/spec/mongo/uri_option_parsing_spec.rb +38 -5
- data/spec/runners/change_streams/test.rb +1 -1
- data/spec/runners/cmap.rb +1 -1
- data/spec/runners/connection_string.rb +7 -3
- data/spec/runners/crud/operation.rb +5 -3
- data/spec/runners/crud/requirement.rb +1 -0
- data/spec/runners/crud.rb +1 -1
- data/spec/runners/sdam.rb +2 -1
- data/spec/runners/transactions/test.rb +2 -2
- data/spec/runners/unified/assertions.rb +2 -3
- data/spec/runners/unified/event_subscriber.rb +2 -2
- data/spec/runners/unified/support_operations.rb +10 -2
- data/spec/runners/unified/test.rb +3 -0
- data/spec/runners/unified.rb +1 -1
- data/spec/shared/lib/mrss/cluster_config.rb +6 -1
- data/spec/shared/lib/mrss/constraints.rb +11 -5
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
- data/spec/shared/share/Dockerfile.erb +5 -4
- data/spec/shared/shlib/server.sh +70 -20
- data/spec/spec_tests/change_streams_spec.rb +1 -1
- data/spec/spec_tests/cmap_spec.rb +4 -1
- data/spec/spec_tests/command_monitoring_spec.rb +2 -2
- data/spec/spec_tests/data/command_monitoring/find.yml +9 -9
- data/spec/spec_tests/data/crud/read/aggregate-collation.yml +2 -1
- data/spec/spec_tests/data/crud/read/aggregate-out.yml +1 -0
- data/spec/spec_tests/data/crud/read/count-collation.yml +2 -1
- data/spec/spec_tests/data/crud/read/distinct-collation.yml +2 -1
- data/spec/spec_tests/data/crud/read/find-collation.yml +2 -1
- data/spec/spec_tests/data/crud/write/bulkWrite-collation.yml +2 -1
- data/spec/spec_tests/data/crud/write/deleteMany-collation.yml +2 -1
- data/spec/spec_tests/data/crud/write/deleteOne-collation.yml +2 -1
- data/spec/spec_tests/data/crud/write/findOneAndDelete-collation.yml +3 -2
- data/spec/spec_tests/data/crud/write/findOneAndReplace-collation.yml +2 -1
- data/spec/spec_tests/data/crud/write/findOneAndUpdate-collation.yml +3 -2
- data/spec/spec_tests/data/crud/write/replaceOne-collation.yml +3 -2
- data/spec/spec_tests/data/crud/write/updateMany-collation.yml +2 -1
- data/spec/spec_tests/data/crud/write/updateOne-collation.yml +2 -1
- data/spec/spec_tests/data/load_balancers/event-monitoring.yml +99 -0
- data/spec/spec_tests/data/load_balancers/lb-connection-establishment.yml +36 -0
- data/spec/spec_tests/data/load_balancers/non-lb-connection-establishment.yml +56 -0
- data/spec/spec_tests/data/load_balancers/server-selection.yml +50 -0
- data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch-serverErrors.yml +1 -1
- data/spec/spec_tests/data/retryable_reads/changeStreams-client.watch.yml +1 -1
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch-serverErrors.yml +1 -1
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.coll.watch.yml +1 -1
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch-serverErrors.yml +1 -1
- data/spec/spec_tests/data/retryable_reads/changeStreams-db.watch.yml +1 -1
- data/spec/spec_tests/data/retryable_reads/mapReduce.yml +3 -1
- data/spec/spec_tests/data/sdam/load-balanced/discover_load_balancer.yml +25 -0
- data/spec/spec_tests/data/sdam_integration/find-network-error.yml +2 -0
- data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +2 -0
- data/spec/spec_tests/data/sdam_integration/hello-command-error.yml +3 -1
- data/spec/spec_tests/data/sdam_integration/hello-network-error.yml +3 -1
- data/spec/spec_tests/data/sdam_integration/hello-timeout.yml +2 -0
- data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +2 -0
- data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +2 -0
- data/spec/spec_tests/data/sdam_monitoring/load_balancer.yml +65 -0
- data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-directConnection.yml +13 -0
- data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-replicaSet-errors.yml +6 -0
- data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-multiple-hosts.yml +5 -0
- data/spec/spec_tests/data/seed_list_discovery/load-balanced/loadBalanced-true-txt.yml +10 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-false.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/direct-connection-true.yml +0 -0
- data/spec/spec_tests/data/seed_list_discovery/replica-set/encoded-userinfo-and-db.yml +15 -0
- data/spec/spec_tests/data/seed_list_discovery/replica-set/loadBalanced-false-txt.yml +10 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/longer-parent-in-return.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/misformatted-option.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/no-results.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/not-enough-parts.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-result-default-port.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record-multiple-strings.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/one-txt-record.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch1.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch2.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch3.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch4.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/parent-part-mismatch5.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-too-short.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/returned-parent-wrong.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-default-port.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-results-nonstandard-port.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/two-txt-records.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-not-allowed-option.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-ssl-option.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-overridden-uri-option.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/txt-record-with-unallowed-option.yml +0 -0
- data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-admin-database.yml +13 -0
- data/spec/spec_tests/data/seed_list_discovery/replica-set/uri-with-auth.yml +12 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-port.yml +0 -0
- data/spec/spec_tests/data/{dns_seedlist_discovery → seed_list_discovery/replica-set}/uri-with-two-hosts.yml +0 -0
- data/spec/spec_tests/data/transactions/retryable-abort-errorLabels.yml +2 -0
- data/spec/spec_tests/data/transactions/retryable-abort.yml +2 -0
- data/spec/spec_tests/data/transactions/retryable-commit-errorLabels.yml +2 -0
- data/spec/spec_tests/data/transactions/retryable-commit.yml +2 -0
- data/spec/spec_tests/data/transactions/retryable-writes.yml +2 -0
- data/spec/spec_tests/data/uri_options/connection-options.yml +60 -0
- data/spec/spec_tests/load_balancers_spec.rb +15 -0
- data/spec/spec_tests/retryable_reads_spec.rb +2 -2
- data/spec/spec_tests/retryable_writes_spec.rb +1 -1
- data/spec/spec_tests/sdam_integration_spec.rb +1 -1
- data/spec/spec_tests/sdam_monitoring_spec.rb +10 -5
- data/spec/spec_tests/sdam_spec.rb +1 -1
- data/spec/spec_tests/seed_list_discovery_spec.rb +118 -0
- data/spec/spec_tests/uri_options_spec.rb +4 -4
- data/spec/stress/fork_reconnect_stress_spec.rb +1 -5
- data/spec/stress/push_monitor_close_spec.rb +44 -0
- data/spec/support/certificates/atlas-ocsp-ca.crt +82 -90
- data/spec/support/certificates/atlas-ocsp.crt +127 -122
- data/spec/support/common_shortcuts.rb +2 -3
- data/spec/support/matchers.rb +13 -0
- data/spec/support/shared/auth_context.rb +16 -0
- data/spec/support/shared/session.rb +2 -2
- data/spec/support/spec_config.rb +10 -11
- data/spec/support/using_hash.rb +31 -0
- data/spec/support/utils.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1077 -1029
- metadata.gz.sig +0 -0
- data/lib/mongo/collection/view/builder/find_command.rb +0 -173
- data/lib/mongo/collection/view/builder/op_query.rb +0 -94
- data/lib/mongo/cursor/builder/get_more_command.rb +0 -80
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +0 -111
- data/lib/mongo/cursor/builder/op_get_more.rb +0 -64
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +0 -106
- data/lib/mongo/server/context.rb +0 -72
- data/spec/mongo/cursor/builder/op_kill_cursors_spec.rb +0 -66
- data/spec/runners/unified/using_hash.rb +0 -34
- data/spec/spec_tests/dns_seedlist_discovery_spec.rb +0 -79
- data/spec/support/event_subscriber.rb +0 -221
@@ -141,6 +141,8 @@ module Mongo
|
|
141
141
|
# @option options [ Hash ] :read The read preference to use for the
|
142
142
|
# query. If none is provided, the collection's default read preference
|
143
143
|
# is used.
|
144
|
+
# @option options [ Hash ] :read_concern The read concern to use for
|
145
|
+
# the query.
|
144
146
|
# @option options [ true | false ] :show_disk_loc Return disk location
|
145
147
|
# info as a field in each doc.
|
146
148
|
# @option options [ Integer ] :skip The number of documents to skip.
|
@@ -153,7 +155,19 @@ module Mongo
|
|
153
155
|
def initialize(collection, filter = {}, options = {})
|
154
156
|
validate_doc!(filter)
|
155
157
|
@collection = collection
|
156
|
-
|
158
|
+
|
159
|
+
filter = BSON::Document.new(filter)
|
160
|
+
options = BSON::Document.new(options)
|
161
|
+
|
162
|
+
# This is when users pass $query in filter and other modifiers
|
163
|
+
# alongside?
|
164
|
+
query = filter.delete(:$query)
|
165
|
+
# This makes modifiers contain the filter if filter wasn't
|
166
|
+
# given via $query but as top-level keys, presumably
|
167
|
+
# downstream code ignores non-modifier keys in the modifiers?
|
168
|
+
modifiers = filter.merge(options.delete(:modifiers) || {})
|
169
|
+
@filter = (query || filter).freeze
|
170
|
+
@options = Operation::Find::Builder::Modifiers.map_driver_options(modifiers).merge!(options).freeze
|
157
171
|
end
|
158
172
|
|
159
173
|
# Get a human-readable string representation of +View+.
|
@@ -189,30 +203,10 @@ module Mongo
|
|
189
203
|
@filter = other.filter.dup
|
190
204
|
end
|
191
205
|
|
192
|
-
def parse_parameters!(filter, options)
|
193
|
-
query = filter.delete(QUERY)
|
194
|
-
modifiers = (filter || {}).merge(options.delete(MODIFIERS) || {})
|
195
|
-
@filter = (query || filter).freeze
|
196
|
-
@options = Builder::Modifiers.map_driver_options(modifiers).merge!(options).freeze
|
197
|
-
end
|
198
|
-
|
199
206
|
def new(options)
|
200
207
|
View.new(collection, filter, options)
|
201
208
|
end
|
202
209
|
|
203
|
-
def apply_collation!(doc, server, opts = {})
|
204
|
-
if coll = doc[:collation] || opts[:collation] || opts['collation'] || collation
|
205
|
-
validate_collation!(server, coll)
|
206
|
-
doc[:collation] = coll
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def validate_collation!(server, coll)
|
211
|
-
if coll && !server.with_connection { |connection| connection.features }.collation_enabled?
|
212
|
-
raise Error::UnsupportedCollation.new
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
210
|
def view; self; end
|
217
211
|
|
218
212
|
def with_session(opts = {}, &block)
|
data/lib/mongo/collection.rb
CHANGED
@@ -251,7 +251,7 @@ module Mongo
|
|
251
251
|
# TODO put the list of read options in a class-level constant when
|
252
252
|
# we figure out what the full set of them is.
|
253
253
|
options = Hash[self.options.reject do |key, value|
|
254
|
-
%w(read read_preference).include?(key.to_s)
|
254
|
+
%w(read read_preference read_concern).include?(key.to_s)
|
255
255
|
end]
|
256
256
|
options.update(Utils.slice_hash(opts, *TIME_SERIES_OPTIONS.keys))
|
257
257
|
# Converting Ruby spelled time series options to server style.
|
@@ -269,17 +269,17 @@ module Mongo
|
|
269
269
|
else
|
270
270
|
self.write_concern
|
271
271
|
end
|
272
|
-
server = next_primary(nil, session)
|
273
|
-
if (options[:collation] || options[Operation::COLLATION]) && !server.with_connection { |connection| connection.features }.collation_enabled?
|
274
|
-
raise Error::UnsupportedCollation
|
275
|
-
end
|
276
272
|
|
277
|
-
Operation::
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
273
|
+
context = Operation::Context.new(client: client, session: session)
|
274
|
+
Operation::Create.new(
|
275
|
+
selector: operation,
|
276
|
+
db_name: database.name,
|
277
|
+
write_concern: write_concern,
|
278
|
+
session: session,
|
279
|
+
# Note that these are collection options, collation isn't
|
280
|
+
# taken from options passed to the create method.
|
281
|
+
collation: options[:collation] || options['collation'],
|
282
|
+
).execute(next_primary(nil, session), context: context)
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
@@ -353,8 +353,8 @@ module Mongo
|
|
353
353
|
# @option options [ true, false ] :no_cursor_timeout The server normally times out idle
|
354
354
|
# cursors after an inactivity period (10 minutes) to prevent excess memory use.
|
355
355
|
# Set this option to prevent that.
|
356
|
-
# @option options [ true, false ] :oplog_replay
|
357
|
-
# should not set.
|
356
|
+
# @option options [ true, false ] :oplog_replay For internal replication
|
357
|
+
# use only, applications should not set this option.
|
358
358
|
# @option options [ Hash ] :projection The fields to include or exclude from each doc
|
359
359
|
# in the result set.
|
360
360
|
# @option options [ Session ] :session The session to use.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Copyright (C) 2021 MongoDB Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
module Mongo
|
19
|
+
class Cursor
|
20
|
+
|
21
|
+
# This class contains the operation specification for KillCursors.
|
22
|
+
#
|
23
|
+
# Its purpose is to ensure we don't misspell attribute names accidentally.
|
24
|
+
#
|
25
|
+
# @api private
|
26
|
+
class KillSpec
|
27
|
+
|
28
|
+
def initialize(cursor_id:, coll_name:, db_name:, service_id:)
|
29
|
+
@cursor_id = cursor_id
|
30
|
+
@coll_name = coll_name
|
31
|
+
@db_name = db_name
|
32
|
+
@service_id = service_id
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :cursor_id, :coll_name, :db_name, :service_id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/mongo/cursor.rb
CHANGED
@@ -15,8 +15,6 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
require 'mongo/cursor/builder'
|
19
|
-
|
20
18
|
module Mongo
|
21
19
|
|
22
20
|
# Client-side representation of an iterator over a query result set on
|
@@ -69,6 +67,10 @@ module Mongo
|
|
69
67
|
#
|
70
68
|
# @since 2.0.0
|
71
69
|
def initialize(view, result, server, options = {})
|
70
|
+
unless result.is_a?(Operation::Result)
|
71
|
+
raise ArgumentError, "Second argument must be a Mongo::Operation::Result: #{result.inspect}"
|
72
|
+
end
|
73
|
+
|
72
74
|
@view = view
|
73
75
|
@server = server
|
74
76
|
@initial_result = result
|
@@ -82,9 +84,8 @@ module Mongo
|
|
82
84
|
@session = @options[:session]
|
83
85
|
unless closed?
|
84
86
|
register
|
85
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(
|
87
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(kill_spec,
|
86
88
|
cluster,
|
87
|
-
kill_cursors_op_spec,
|
88
89
|
server,
|
89
90
|
@session))
|
90
91
|
end
|
@@ -93,23 +94,25 @@ module Mongo
|
|
93
94
|
# @api private
|
94
95
|
attr_reader :server
|
95
96
|
|
97
|
+
# @api private
|
98
|
+
attr_reader :initial_result
|
99
|
+
|
96
100
|
# Finalize the cursor for garbage collection. Schedules this cursor to be included
|
97
101
|
# in a killCursors operation executed by the Cluster's CursorReaper.
|
98
102
|
#
|
99
|
-
# @
|
100
|
-
# Cursor.finalize(id, cluster, op, server)
|
101
|
-
#
|
102
|
-
# @param [ Integer ] cursor_id The cursor's id.
|
103
|
+
# @param [ Cursor::KillSpec ] kill_spec The KillCursor operation specification.
|
103
104
|
# @param [ Mongo::Cluster ] cluster The cluster associated with this cursor and its server.
|
104
|
-
# @param [ Hash ] op_spec The killCursors operation specification.
|
105
105
|
# @param [ Mongo::Server ] server The server to send the killCursors operation to.
|
106
106
|
#
|
107
107
|
# @return [ Proc ] The Finalizer.
|
108
108
|
#
|
109
|
-
# @
|
110
|
-
def self.finalize(
|
109
|
+
# @api private
|
110
|
+
def self.finalize(kill_spec, cluster, server, session)
|
111
|
+
unless KillSpec === kill_spec
|
112
|
+
raise ArgumentError, "First argument must be a KillSpec: #{kill_spec.inspect}"
|
113
|
+
end
|
111
114
|
proc do
|
112
|
-
cluster.schedule_kill_cursor(
|
115
|
+
cluster.schedule_kill_cursor(kill_spec, server)
|
113
116
|
session.end_session if session && session.implicit?
|
114
117
|
end
|
115
118
|
end
|
@@ -212,10 +215,12 @@ module Mongo
|
|
212
215
|
unless closed?
|
213
216
|
if exhausted?
|
214
217
|
close
|
218
|
+
@fully_iterated = true
|
215
219
|
raise StopIteration
|
216
220
|
end
|
217
221
|
@documents = get_more
|
218
222
|
else
|
223
|
+
@fully_iterated = true
|
219
224
|
raise StopIteration
|
220
225
|
end
|
221
226
|
else
|
@@ -232,6 +237,9 @@ module Mongo
|
|
232
237
|
# over the last document, or if the batch is empty
|
233
238
|
if @documents.size <= 1
|
234
239
|
cache_batch_resume_token
|
240
|
+
if closed?
|
241
|
+
@fully_iterated = true
|
242
|
+
end
|
235
243
|
end
|
236
244
|
|
237
245
|
return @documents.shift
|
@@ -274,7 +282,13 @@ module Mongo
|
|
274
282
|
|
275
283
|
unregister
|
276
284
|
read_with_one_retry do
|
277
|
-
|
285
|
+
spec = {
|
286
|
+
coll_name: collection_name,
|
287
|
+
db_name: database.name,
|
288
|
+
cursor_ids: [id],
|
289
|
+
}
|
290
|
+
op = Operation::KillCursors.new(spec)
|
291
|
+
execute_operation(op)
|
278
292
|
end
|
279
293
|
|
280
294
|
nil
|
@@ -349,7 +363,22 @@ module Mongo
|
|
349
363
|
# doing so may result in silent data loss, the driver no longer retries
|
350
364
|
# getMore operations in any circumstance.
|
351
365
|
# https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#qa
|
352
|
-
process(get_more_operation
|
366
|
+
process(execute_operation(get_more_operation))
|
367
|
+
end
|
368
|
+
|
369
|
+
# @api private
|
370
|
+
def kill_spec
|
371
|
+
KillSpec.new(
|
372
|
+
cursor_id: id,
|
373
|
+
coll_name: collection_name,
|
374
|
+
db_name: database.name,
|
375
|
+
service_id: initial_result.connection_description.service_id,
|
376
|
+
)
|
377
|
+
end
|
378
|
+
|
379
|
+
# @api private
|
380
|
+
def fully_iterated?
|
381
|
+
!!@fully_iterated
|
353
382
|
end
|
354
383
|
|
355
384
|
private
|
@@ -369,11 +398,24 @@ module Mongo
|
|
369
398
|
end
|
370
399
|
|
371
400
|
def get_more_operation
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
401
|
+
spec = {
|
402
|
+
session: @session,
|
403
|
+
db_name: database.name,
|
404
|
+
coll_name: collection_name,
|
405
|
+
cursor_id: id,
|
406
|
+
# 3.2+ servers use batch_size, 3.0- servers use to_return.
|
407
|
+
# TODO should to_return be calculated in the operation layer?
|
408
|
+
batch_size: batch_size,
|
409
|
+
to_return: to_return,
|
410
|
+
max_time_ms: if view.respond_to?(:max_await_time_ms) &&
|
411
|
+
view.max_await_time_ms &&
|
412
|
+
view.options[:await_data]
|
413
|
+
then
|
414
|
+
view.max_await_time_ms
|
415
|
+
else
|
416
|
+
nil
|
417
|
+
end,
|
418
|
+
}
|
377
419
|
Operation::GetMore.new(spec)
|
378
420
|
end
|
379
421
|
|
@@ -381,18 +423,6 @@ module Mongo
|
|
381
423
|
@session.end_session if @session && @session.implicit?
|
382
424
|
end
|
383
425
|
|
384
|
-
def kill_cursors_operation
|
385
|
-
Operation::KillCursors.new(kill_cursors_op_spec)
|
386
|
-
end
|
387
|
-
|
388
|
-
def kill_cursors_op_spec
|
389
|
-
if @server.with_connection { |connection| connection.features }.find_command_enabled?
|
390
|
-
Builder::KillCursorsCommand.new(self).specification
|
391
|
-
else
|
392
|
-
Builder::OpKillCursors.new(self).specification
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
426
|
def limited?
|
397
427
|
limit ? limit > 0 : false
|
398
428
|
end
|
@@ -433,5 +463,16 @@ module Mongo
|
|
433
463
|
def unregister
|
434
464
|
cluster.unregister_cursor(@cursor_id)
|
435
465
|
end
|
466
|
+
|
467
|
+
def execute_operation(op)
|
468
|
+
context = Operation::Context.new(
|
469
|
+
client: client,
|
470
|
+
session: @session,
|
471
|
+
service_id: initial_result.connection_description.service_id,
|
472
|
+
)
|
473
|
+
op.execute(@server, context: context)
|
474
|
+
end
|
436
475
|
end
|
437
476
|
end
|
477
|
+
|
478
|
+
require 'mongo/cursor/kill_spec'
|
data/lib/mongo/database/view.rb
CHANGED
@@ -68,7 +68,7 @@ module Mongo
|
|
68
68
|
send_initial_query(server, session, options.merge(name_only: true))
|
69
69
|
end
|
70
70
|
cursor.map do |info|
|
71
|
-
if cursor.
|
71
|
+
if cursor.initial_result.connection_description.features.list_collections_enabled?
|
72
72
|
info['name']
|
73
73
|
else
|
74
74
|
(info['name'] &&
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Copyright (C) 2021 MongoDB Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
module Mongo
|
19
|
+
class Error
|
20
|
+
|
21
|
+
# Raised when the driver is in load-balancing mode but a connection
|
22
|
+
# is established to something other than a mongos.
|
23
|
+
class BadLoadBalancerTarget < Error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Copyright (C) 2021 MongoDB Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
module Mongo
|
19
|
+
class Error
|
20
|
+
|
21
|
+
# Raised when the driver is in load-balancing mode via the URI option
|
22
|
+
# but a connection does not report a value in the serviceId field.
|
23
|
+
class MissingServiceId < Error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Copyright (C) 2021 MongoDB Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
module Mongo
|
19
|
+
class Error
|
20
|
+
|
21
|
+
# Raised when the driver requires a connection to a particular service
|
22
|
+
# but no matching connections exist in the connection pool.
|
23
|
+
class NoServiceConnectionAvailable < Error
|
24
|
+
# @api private
|
25
|
+
def initialize(message, address:, service_id:)
|
26
|
+
super(message)
|
27
|
+
|
28
|
+
@address = address
|
29
|
+
@service_id = service_id
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [ Mongo::Address ] The address to which a connection was
|
33
|
+
# requested.
|
34
|
+
attr_reader :address
|
35
|
+
|
36
|
+
# @return [ nil | Object ] The service id.
|
37
|
+
attr_reader :service_id
|
38
|
+
|
39
|
+
# @api private
|
40
|
+
def self.generate(address:, service_id:)
|
41
|
+
new(
|
42
|
+
"The connection pool for #{address} does not have a connection for service #{service_id}",
|
43
|
+
address: address,
|
44
|
+
service_id: service_id,
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/mongo/error/notable.rb
CHANGED
@@ -63,6 +63,13 @@ module Mongo
|
|
63
63
|
# @return [ Integer | nil ] Connection pool generation.
|
64
64
|
attr_accessor :generation
|
65
65
|
|
66
|
+
# Returns service id for the connection on which the error occurred.
|
67
|
+
#
|
68
|
+
# @return [ Object | nil ] Service id.
|
69
|
+
#
|
70
|
+
# @api experimental
|
71
|
+
attr_accessor :service_id
|
72
|
+
|
66
73
|
# @api public
|
67
74
|
def to_s
|
68
75
|
super + notes_tail
|
data/lib/mongo/error.rb
CHANGED
@@ -168,6 +168,7 @@ module Mongo
|
|
168
168
|
end
|
169
169
|
|
170
170
|
require 'mongo/error/auth_error'
|
171
|
+
require 'mongo/error/bad_load_balancer_target'
|
171
172
|
require 'mongo/error/sdam_error_detection'
|
172
173
|
require 'mongo/error/parser'
|
173
174
|
require 'mongo/error/write_retryable'
|
@@ -217,6 +218,7 @@ require 'mongo/error/mismatched_domain'
|
|
217
218
|
require 'mongo/error/mongocryptd_spawn_error'
|
218
219
|
require 'mongo/error/multi_index_drop'
|
219
220
|
require 'mongo/error/need_primary_server'
|
221
|
+
require 'mongo/error/no_service_connection_available'
|
220
222
|
require 'mongo/error/no_server_available'
|
221
223
|
require 'mongo/error/no_srv_records'
|
222
224
|
require 'mongo/error/session_ended'
|
@@ -235,6 +237,7 @@ require 'mongo/error/missing_file_chunk'
|
|
235
237
|
require 'mongo/error/missing_password'
|
236
238
|
require 'mongo/error/missing_resume_token'
|
237
239
|
require 'mongo/error/missing_scram_server_signature'
|
240
|
+
require 'mongo/error/missing_service_id'
|
238
241
|
require 'mongo/error/server_api_conflict'
|
239
242
|
require 'mongo/error/server_api_not_supported'
|
240
243
|
require 'mongo/error/unknown_payload_type'
|
data/lib/mongo/grid/fs_bucket.rb
CHANGED
@@ -508,8 +508,27 @@ module Mongo
|
|
508
508
|
|
509
509
|
def ensure_indexes!
|
510
510
|
if files_collection.find({}, limit: 1, projection: { _id: 1 }).first.nil?
|
511
|
-
|
512
|
-
|
511
|
+
create_index_if_missing!(files_collection, FSBucket::FILES_INDEX)
|
512
|
+
end
|
513
|
+
|
514
|
+
if chunks_collection.find({}, limit: 1, projection: { _id: 1 }).first.nil?
|
515
|
+
create_index_if_missing!(chunks_collection, FSBucket::CHUNKS_INDEX, :unique => true)
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
def create_index_if_missing!(collection, index_spec, options = {})
|
520
|
+
indexes_view = collection.indexes
|
521
|
+
begin
|
522
|
+
if indexes_view.get(index_spec).nil?
|
523
|
+
indexes_view.create_one(index_spec, options)
|
524
|
+
end
|
525
|
+
rescue Mongo::Error::OperationFailure => e
|
526
|
+
# proceed with index creation if a NamespaceNotFound error is thrown
|
527
|
+
if e.code == 26
|
528
|
+
indexes_view.create_one(index_spec, options)
|
529
|
+
else
|
530
|
+
raise
|
531
|
+
end
|
513
532
|
end
|
514
533
|
end
|
515
534
|
end
|
data/lib/mongo/id.rb
CHANGED
@@ -16,9 +16,10 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
18
|
module Mongo
|
19
|
-
# This module abstracts the functionality for generating sequential
|
20
|
-
# instances of the class. It defines the method
|
21
|
-
#
|
19
|
+
# This module abstracts the functionality for generating sequential
|
20
|
+
# unique integer IDs for instances of the class. It defines the method
|
21
|
+
# #next_id on the class that includes it. The implementation ensures that
|
22
|
+
# the IDs will be unique even when called from multiple threads.
|
22
23
|
#
|
23
24
|
# @example Include the Id module.
|
24
25
|
# class Foo
|
@@ -29,8 +30,9 @@ module Mongo
|
|
29
30
|
# foo.next_id # => 1
|
30
31
|
# foo.next_id # => 2
|
31
32
|
#
|
32
|
-
# Classes which include Id should _not_ access `@@id` or `@@id_lock`
|
33
|
-
# should call `#next_id` in `#initialize` and save
|
33
|
+
# Classes which include Id should _not_ access `@@id` or `@@id_lock`
|
34
|
+
# directly; instead, they should call `#next_id` in `#initialize` and save
|
35
|
+
# the result in the instance being created.
|
34
36
|
#
|
35
37
|
# @example Save the ID in the instance of the including class.
|
36
38
|
# class Bar
|
data/lib/mongo/index/view.rb
CHANGED
@@ -129,7 +129,10 @@ module Mongo
|
|
129
129
|
# @option options [ String | Integer ] :commit_quorum Specify how many
|
130
130
|
# data-bearing members of a replica set, including the primary, must
|
131
131
|
# complete the index builds successfully before the primary marks
|
132
|
-
# the indexes as ready.
|
132
|
+
# the indexes as ready. Potential values are:
|
133
|
+
# - an integer from 0 to the number of members of the replica set
|
134
|
+
# - "majority" indicating that a majority of data bearing nodes must vote
|
135
|
+
# - "votingMembers" which means that all voting data bearing nodes must vote
|
133
136
|
# @option options [ Session ] :session The session to use for the operation.
|
134
137
|
#
|
135
138
|
# @note Note that the options listed may be subset of those available.
|
@@ -177,7 +180,10 @@ module Mongo
|
|
177
180
|
# The following options are accepted:
|
178
181
|
# - commit_quorum: Specify how many data-bearing members of a replica set,
|
179
182
|
# including the primary, must complete the index builds successfully
|
180
|
-
# before the primary marks the indexes as ready.
|
183
|
+
# before the primary marks the indexes as ready. Potential values are:
|
184
|
+
# - an integer from 0 to the number of members of the replica set
|
185
|
+
# - "majority" indicating that a majority of data bearing nodes must vote
|
186
|
+
# - "votingMembers" which means that all voting data bearing nodes must vote
|
181
187
|
# - session: The session to use.
|
182
188
|
#
|
183
189
|
# @return [ Result ] The result of the command.
|
@@ -193,17 +199,6 @@ module Mongo
|
|
193
199
|
client.send(:with_session, @options.merge(options)) do |session|
|
194
200
|
server = next_primary(nil, session)
|
195
201
|
|
196
|
-
# While server versions 3.4 and newer generally perform option
|
197
|
-
# validation, there was a bug on server versions 4.2.0 - 4.2.5 where
|
198
|
-
# the server would accept the commitQuorum option and use it internally
|
199
|
-
# (see SERVER-47193). As a result, the drivers specifications require
|
200
|
-
# drivers to perform validation and raise an error when the commitQuorum
|
201
|
-
# option is passed to servers that don't support it.
|
202
|
-
description = server.with_connection { |connection| connection.description }
|
203
|
-
if description.max_wire_version < 9 && options[:commit_quorum]
|
204
|
-
raise Error::UnsupportedOption.commit_quorum_error
|
205
|
-
end
|
206
|
-
|
207
202
|
indexes = normalize_models(models, server)
|
208
203
|
indexes.each do |index|
|
209
204
|
if index[:bucketSize] || index['bucketSize']
|
@@ -216,10 +211,9 @@ module Mongo
|
|
216
211
|
db_name: database.name,
|
217
212
|
coll_name: collection.name,
|
218
213
|
session: session,
|
219
|
-
commit_quorum: options[:commit_quorum]
|
220
|
-
|
221
|
-
|
222
|
-
spec[:write_concern] = write_concern if description.features.collation_enabled?
|
214
|
+
commit_quorum: options[:commit_quorum],
|
215
|
+
write_concern: write_concern,
|
216
|
+
}
|
223
217
|
|
224
218
|
Operation::CreateIndex.new(spec).execute(server, context: Operation::Context.new(client: client, session: session))
|
225
219
|
end
|
@@ -292,13 +286,13 @@ module Mongo
|
|
292
286
|
def drop_by_name(name)
|
293
287
|
client.send(:with_session, @options) do |session|
|
294
288
|
spec = {
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
289
|
+
db_name: database.name,
|
290
|
+
coll_name: collection.name,
|
291
|
+
index_name: name,
|
292
|
+
session: session,
|
293
|
+
write_concern: write_concern,
|
294
|
+
}
|
300
295
|
server = next_primary(nil, session)
|
301
|
-
spec[:write_concern] = write_concern if server.with_connection { |connection| connection.features }.collation_enabled?
|
302
296
|
Operation::DropIndex.new(spec).execute(server, context: Operation::Context.new(client: client, session: session))
|
303
297
|
end
|
304
298
|
end
|
@@ -329,30 +323,17 @@ module Mongo
|
|
329
323
|
end
|
330
324
|
|
331
325
|
def normalize_models(models, server)
|
332
|
-
|
333
|
-
|
326
|
+
models.map do |model|
|
327
|
+
# Transform options first which gives us a mutable hash
|
328
|
+
Options::Mapper.transform(model, OPTIONS).tap do |model|
|
329
|
+
model[:name] ||= index_name(model.fetch(:key))
|
330
|
+
end
|
334
331
|
end
|
335
332
|
end
|
336
333
|
|
337
334
|
def send_initial_query(server, session)
|
338
335
|
initial_query_op(session).execute(server, context: Operation::Context.new(client: client, session: session))
|
339
336
|
end
|
340
|
-
|
341
|
-
def with_generated_names(models, server)
|
342
|
-
models.dup.each do |model|
|
343
|
-
validate_collation!(model, server)
|
344
|
-
unless model[:name]
|
345
|
-
model[:name] = index_name(model[:key])
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
def validate_collation!(model, server)
|
351
|
-
if (model[:collation] || model[Operation::COLLATION]) &&
|
352
|
-
!server.with_connection { |connection| connection.features }.collation_enabled?
|
353
|
-
raise Error::UnsupportedCollation.new
|
354
|
-
end
|
355
|
-
end
|
356
337
|
end
|
357
338
|
end
|
358
339
|
end
|