mongo 2.13.0.beta1 → 2.14.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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -5
- data/Rakefile +50 -9
- data/lib/mongo.rb +13 -2
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/auth/aws/request.rb +31 -5
- data/lib/mongo/bulk_write.rb +18 -0
- data/lib/mongo/caching_cursor.rb +74 -0
- data/lib/mongo/client.rb +238 -31
- data/lib/mongo/cluster.rb +56 -20
- data/lib/mongo/cluster/sdam_flow.rb +13 -10
- data/lib/mongo/cluster/topology/replica_set_no_primary.rb +3 -2
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/single.rb +2 -2
- data/lib/mongo/collection.rb +66 -24
- data/lib/mongo/collection/view.rb +24 -20
- data/lib/mongo/collection/view/aggregation.rb +25 -4
- data/lib/mongo/collection/view/builder/find_command.rb +38 -18
- data/lib/mongo/collection/view/explainable.rb +27 -8
- data/lib/mongo/collection/view/iterable.rb +72 -12
- data/lib/mongo/collection/view/readable.rb +19 -3
- data/lib/mongo/collection/view/writable.rb +55 -5
- data/lib/mongo/crypt/encryption_io.rb +6 -6
- data/lib/mongo/cursor.rb +16 -3
- data/lib/mongo/database.rb +37 -4
- data/lib/mongo/database/view.rb +18 -3
- data/lib/mongo/distinguishing_semaphore.rb +55 -0
- data/lib/mongo/error.rb +5 -0
- data/lib/mongo/error/invalid_read_concern.rb +28 -0
- data/lib/mongo/error/invalid_server_auth_host.rb +22 -0
- data/lib/mongo/error/invalid_session.rb +2 -1
- data/lib/mongo/error/operation_failure.rb +11 -5
- data/lib/mongo/error/server_certificate_revoked.rb +22 -0
- data/lib/mongo/error/sessions_not_supported.rb +35 -0
- data/lib/mongo/error/unsupported_option.rb +14 -12
- data/lib/mongo/event/base.rb +6 -0
- data/lib/mongo/grid/file.rb +5 -0
- data/lib/mongo/grid/file/chunk.rb +2 -0
- data/lib/mongo/grid/fs_bucket.rb +15 -13
- data/lib/mongo/grid/stream/write.rb +9 -3
- data/lib/mongo/index/view.rb +3 -0
- data/lib/mongo/lint.rb +2 -1
- data/lib/mongo/logger.rb +3 -3
- data/lib/mongo/monitoring.rb +38 -0
- data/lib/mongo/monitoring/command_log_subscriber.rb +10 -2
- data/lib/mongo/monitoring/event/command_failed.rb +11 -0
- data/lib/mongo/monitoring/event/command_started.rb +37 -2
- data/lib/mongo/monitoring/event/command_succeeded.rb +11 -0
- data/lib/mongo/monitoring/event/server_closed.rb +1 -1
- data/lib/mongo/monitoring/event/server_description_changed.rb +27 -4
- data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +9 -2
- data/lib/mongo/monitoring/event/server_heartbeat_started.rb +9 -2
- data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +9 -2
- data/lib/mongo/monitoring/event/server_opening.rb +1 -1
- data/lib/mongo/monitoring/event/topology_changed.rb +1 -1
- data/lib/mongo/monitoring/event/topology_closed.rb +1 -1
- data/lib/mongo/monitoring/event/topology_opening.rb +1 -1
- data/lib/mongo/monitoring/publishable.rb +6 -3
- data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +9 -1
- data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +1 -1
- data/lib/mongo/operation.rb +2 -0
- data/lib/mongo/operation/aggregate/result.rb +9 -8
- data/lib/mongo/operation/collections_info/command.rb +5 -0
- data/lib/mongo/operation/collections_info/result.rb +18 -1
- data/lib/mongo/operation/delete/bulk_result.rb +2 -0
- data/lib/mongo/operation/delete/result.rb +3 -0
- data/lib/mongo/operation/explain/command.rb +4 -0
- data/lib/mongo/operation/explain/legacy.rb +4 -0
- data/lib/mongo/operation/explain/op_msg.rb +6 -0
- data/lib/mongo/operation/explain/result.rb +3 -0
- data/lib/mongo/operation/find/legacy/result.rb +2 -0
- data/lib/mongo/operation/find/result.rb +13 -0
- data/lib/mongo/operation/get_more/result.rb +3 -0
- data/lib/mongo/operation/indexes/result.rb +5 -0
- data/lib/mongo/operation/insert/bulk_result.rb +5 -0
- data/lib/mongo/operation/insert/result.rb +5 -0
- data/lib/mongo/operation/list_collections/result.rb +5 -0
- data/lib/mongo/operation/map_reduce/result.rb +10 -0
- data/lib/mongo/operation/parallel_scan/result.rb +4 -0
- data/lib/mongo/operation/result.rb +35 -6
- data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
- data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
- data/lib/mongo/operation/shared/executable.rb +1 -0
- data/lib/mongo/operation/shared/idable.rb +2 -1
- data/lib/mongo/operation/shared/limited.rb +1 -0
- data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
- data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +1 -0
- data/lib/mongo/operation/shared/specifiable.rb +1 -0
- data/lib/mongo/operation/shared/write.rb +1 -0
- data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
- data/lib/mongo/operation/update/legacy/result.rb +7 -0
- data/lib/mongo/operation/update/result.rb +8 -0
- data/lib/mongo/operation/users_info/result.rb +3 -0
- data/lib/mongo/protocol/message.rb +47 -10
- data/lib/mongo/protocol/msg.rb +34 -1
- data/lib/mongo/protocol/query.rb +36 -0
- data/lib/mongo/protocol/serializers.rb +5 -2
- data/lib/mongo/query_cache.rb +242 -0
- data/lib/mongo/retryable.rb +8 -1
- data/lib/mongo/server.rb +15 -4
- data/lib/mongo/server/app_metadata.rb +27 -3
- data/lib/mongo/server/connection.rb +4 -4
- data/lib/mongo/server/connection_base.rb +38 -12
- data/lib/mongo/server/connection_common.rb +2 -2
- data/lib/mongo/server/connection_pool.rb +3 -0
- data/lib/mongo/server/description.rb +13 -1
- data/lib/mongo/server/monitor.rb +76 -44
- data/lib/mongo/server/monitor/connection.rb +57 -9
- data/lib/mongo/server/pending_connection.rb +14 -4
- data/lib/mongo/server/push_monitor.rb +173 -0
- data/{spec/runners/transactions/context.rb → lib/mongo/server/push_monitor/connection.rb} +9 -14
- data/lib/mongo/server_selector.rb +0 -1
- data/lib/mongo/server_selector/base.rb +583 -1
- data/lib/mongo/server_selector/nearest.rb +1 -6
- data/lib/mongo/server_selector/primary.rb +1 -6
- data/lib/mongo/server_selector/primary_preferred.rb +7 -10
- data/lib/mongo/server_selector/secondary.rb +1 -6
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -7
- data/lib/mongo/session.rb +7 -1
- data/lib/mongo/socket.rb +26 -12
- data/lib/mongo/socket/ocsp_cache.rb +97 -0
- data/lib/mongo/socket/ocsp_verifier.rb +368 -0
- data/lib/mongo/socket/ssl.rb +46 -25
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/srv/monitor.rb +7 -13
- data/lib/mongo/srv/resolver.rb +14 -10
- data/lib/mongo/timeout.rb +2 -0
- data/lib/mongo/topology_version.rb +9 -0
- data/lib/mongo/uri.rb +21 -390
- data/lib/mongo/uri/options_mapper.rb +582 -0
- data/lib/mongo/uri/srv_protocol.rb +3 -2
- data/lib/mongo/utils.rb +73 -0
- data/lib/mongo/version.rb +1 -1
- data/spec/NOTES.aws-auth.md +12 -7
- data/spec/README.aws-auth.md +2 -2
- data/spec/README.md +63 -1
- data/spec/integration/awaited_ismaster_spec.rb +28 -0
- data/spec/integration/bson_symbol_spec.rb +4 -2
- data/spec/integration/bulk_write_spec.rb +67 -0
- data/spec/integration/change_stream_examples_spec.rb +6 -2
- data/spec/integration/change_stream_spec.rb +1 -1
- data/spec/integration/check_clean_slate_spec.rb +16 -0
- data/spec/integration/client_authentication_options_spec.rb +92 -28
- data/spec/integration/client_construction_spec.rb +1 -0
- data/spec/integration/client_side_encryption/auto_encryption_bulk_writes_spec.rb +9 -5
- data/spec/integration/connect_single_rs_name_spec.rb +5 -2
- data/spec/integration/connection_pool_populator_spec.rb +4 -2
- data/spec/integration/connection_spec.rb +7 -4
- data/spec/integration/crud_spec.rb +4 -4
- data/spec/integration/cursor_reaping_spec.rb +54 -18
- data/spec/integration/docs_examples_spec.rb +6 -0
- data/spec/integration/fork_reconnect_spec.rb +56 -1
- data/spec/integration/grid_fs_bucket_spec.rb +48 -0
- data/spec/integration/heartbeat_events_spec.rb +4 -23
- data/spec/integration/ocsp_connectivity_spec.rb +26 -0
- data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
- data/spec/integration/ocsp_verifier_spec.rb +334 -0
- data/spec/integration/query_cache_spec.rb +1045 -0
- data/spec/integration/query_cache_transactions_spec.rb +190 -0
- data/spec/integration/read_concern_spec.rb +1 -1
- data/spec/integration/retryable_errors_spec.rb +1 -1
- data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
- data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +4 -2
- data/spec/integration/retryable_writes/shared/performs_modern_retries.rb +3 -3
- data/spec/integration/retryable_writes/shared/performs_no_retries.rb +2 -2
- data/spec/integration/sdam_error_handling_spec.rb +122 -15
- data/spec/integration/sdam_events_spec.rb +80 -6
- data/spec/integration/sdam_prose_spec.rb +64 -0
- data/spec/integration/server_monitor_spec.rb +25 -1
- data/spec/integration/server_selection_spec.rb +36 -0
- data/spec/integration/size_limit_spec.rb +23 -5
- data/spec/integration/srv_monitoring_spec.rb +38 -3
- data/spec/integration/srv_spec.rb +56 -0
- data/spec/integration/ssl_uri_options_spec.rb +2 -2
- data/spec/integration/transactions_examples_spec.rb +17 -7
- data/spec/integration/zlib_compression_spec.rb +25 -0
- data/spec/lite_spec_helper.rb +20 -9
- data/spec/mongo/address_spec.rb +1 -1
- data/spec/mongo/auth/aws/request_region_spec.rb +42 -0
- data/spec/mongo/auth/aws/request_spec.rb +76 -0
- data/spec/mongo/auth/scram_spec.rb +1 -1
- data/spec/mongo/auth/user_spec.rb +1 -1
- data/spec/mongo/bulk_write_spec.rb +2 -2
- data/spec/mongo/caching_cursor_spec.rb +70 -0
- data/spec/mongo/client_construction_spec.rb +386 -3
- data/spec/mongo/client_encryption_spec.rb +16 -10
- data/spec/mongo/client_spec.rb +85 -3
- data/spec/mongo/cluster/topology/replica_set_spec.rb +53 -10
- data/spec/mongo/cluster/topology/sharded_spec.rb +1 -1
- data/spec/mongo/cluster/topology/single_spec.rb +19 -8
- data/spec/mongo/cluster/topology/unknown_spec.rb +1 -1
- data/spec/mongo/cluster/topology_spec.rb +1 -1
- data/spec/mongo/cluster_spec.rb +37 -35
- data/spec/mongo/collection/view/change_stream_resume_spec.rb +7 -7
- data/spec/mongo/collection/view/explainable_spec.rb +87 -4
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
- data/spec/mongo/collection/view/readable_spec.rb +36 -0
- data/spec/mongo/collection_spec.rb +572 -0
- data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/binary_spec.rb +1 -6
- data/spec/mongo/crypt/binding/binary_spec.rb +1 -6
- data/spec/mongo/crypt/binding/context_spec.rb +2 -7
- data/spec/mongo/crypt/binding/helpers_spec.rb +1 -6
- data/spec/mongo/crypt/binding/mongocrypt_spec.rb +2 -7
- data/spec/mongo/crypt/binding/status_spec.rb +1 -6
- data/spec/mongo/crypt/binding/version_spec.rb +1 -6
- data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/status_spec.rb +1 -6
- data/spec/mongo/database_spec.rb +353 -8
- data/spec/mongo/distinguishing_semaphore_spec.rb +63 -0
- data/spec/mongo/error/no_server_available_spec.rb +1 -1
- data/spec/mongo/error/operation_failure_spec.rb +40 -0
- data/spec/mongo/index/view_spec.rb +148 -2
- data/spec/mongo/logger_spec.rb +13 -11
- data/spec/mongo/monitoring/event/server_closed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/server_description_changed_spec.rb +1 -4
- data/spec/mongo/monitoring/event/server_opening_spec.rb +1 -1
- data/spec/mongo/monitoring/event/topology_changed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/topology_closed_spec.rb +1 -1
- data/spec/mongo/monitoring/event/topology_opening_spec.rb +1 -1
- data/spec/mongo/operation/delete/op_msg_spec.rb +3 -3
- data/spec/mongo/operation/insert/command_spec.rb +2 -2
- data/spec/mongo/operation/insert/op_msg_spec.rb +3 -3
- data/spec/mongo/operation/read_preference_op_msg_spec.rb +1 -1
- data/spec/mongo/operation/update/command_spec.rb +2 -2
- data/spec/mongo/operation/update/op_msg_spec.rb +3 -3
- data/spec/mongo/protocol/msg_spec.rb +10 -0
- data/spec/mongo/query_cache_spec.rb +280 -0
- data/spec/mongo/semaphore_spec.rb +51 -0
- data/spec/mongo/server/app_metadata_shared.rb +82 -2
- data/spec/mongo/server/connection_auth_spec.rb +2 -2
- data/spec/mongo/server/connection_pool_spec.rb +7 -3
- data/spec/mongo/server/connection_spec.rb +15 -8
- data/spec/mongo/server/description_spec.rb +18 -0
- data/spec/mongo/server_selector/nearest_spec.rb +23 -23
- data/spec/mongo/server_selector/primary_preferred_spec.rb +26 -26
- data/spec/mongo/server_selector/primary_spec.rb +9 -9
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +22 -22
- data/spec/mongo/server_selector/secondary_spec.rb +18 -18
- data/spec/mongo/server_selector_spec.rb +6 -6
- data/spec/mongo/session_spec.rb +35 -0
- data/spec/mongo/socket/ssl_spec.rb +4 -4
- data/spec/mongo/socket_spec.rb +1 -1
- data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
- data/spec/mongo/uri_option_parsing_spec.rb +11 -11
- data/spec/mongo/uri_spec.rb +68 -41
- data/spec/mongo/utils_spec.rb +39 -0
- data/spec/runners/auth.rb +3 -0
- data/spec/runners/change_streams/test.rb +3 -3
- data/spec/runners/cmap.rb +1 -1
- data/spec/runners/command_monitoring.rb +3 -34
- data/spec/runners/connection_string.rb +35 -124
- data/spec/runners/crud/context.rb +9 -5
- data/spec/runners/crud/operation.rb +59 -27
- data/spec/runners/crud/spec.rb +0 -8
- data/spec/runners/crud/test.rb +1 -1
- data/spec/runners/crud/test_base.rb +0 -19
- data/spec/runners/sdam.rb +2 -2
- data/spec/runners/server_selection.rb +242 -28
- data/spec/runners/transactions.rb +12 -12
- data/spec/runners/transactions/operation.rb +151 -25
- data/spec/runners/transactions/test.rb +62 -18
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/constraints.rb +303 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/spec_tests/cmap_spec.rb +7 -3
- data/spec/spec_tests/command_monitoring_spec.rb +22 -12
- data/spec/spec_tests/crud_spec.rb +1 -1
- data/spec/spec_tests/data/change_streams/change-streams-errors.yml +4 -9
- data/spec/spec_tests/data/change_streams/change-streams-resume-whitelist.yml +66 -0
- data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
- data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
- data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
- data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
- data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/MaxStalenessTooSmall.yml +15 -0
- data/spec/spec_tests/data/max_staleness/ReplicaSetNoPrimary/NoKnownServers.yml +4 -3
- data/spec/spec_tests/data/max_staleness/Unknown/SmallMaxStaleness.yml +1 -0
- data/spec/spec_tests/data/sdam_integration/cancel-server-check.yml +96 -0
- data/spec/spec_tests/data/sdam_integration/connectTimeoutMS.yml +88 -0
- data/spec/spec_tests/data/sdam_integration/find-network-error.yml +83 -0
- data/spec/spec_tests/data/sdam_integration/find-shutdown-error.yml +116 -0
- data/spec/spec_tests/data/sdam_integration/insert-network-error.yml +86 -0
- data/spec/spec_tests/data/sdam_integration/insert-shutdown-error.yml +115 -0
- data/spec/spec_tests/data/sdam_integration/isMaster-command-error.yml +168 -0
- data/spec/spec_tests/data/sdam_integration/isMaster-network-error.yml +162 -0
- data/spec/spec_tests/data/sdam_integration/isMaster-timeout.yml +229 -0
- data/spec/spec_tests/data/sdam_integration/rediscover-quickly-after-step-down.yml +87 -0
- data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
- data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
- data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
- data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
- data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
- data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
- data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
- data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
- data/spec/spec_tests/max_staleness_spec.rb +4 -142
- data/spec/spec_tests/retryable_reads_spec.rb +2 -2
- data/spec/spec_tests/sdam_integration_spec.rb +13 -0
- data/spec/spec_tests/sdam_monitoring_spec.rb +1 -2
- data/spec/spec_tests/server_selection_spec.rb +4 -116
- data/spec/spec_tests/uri_options_spec.rb +31 -33
- data/spec/stress/cleanup_spec.rb +17 -2
- data/spec/stress/connection_pool_stress_spec.rb +10 -8
- data/spec/stress/fork_reconnect_stress_spec.rb +1 -1
- data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
- data/spec/support/certificates/atlas-ocsp.crt +41 -0
- data/spec/support/client_registry.rb +1 -0
- data/spec/support/client_registry_macros.rb +11 -2
- data/spec/support/cluster_config.rb +4 -0
- data/spec/support/common_shortcuts.rb +45 -0
- data/spec/support/constraints.rb +6 -253
- data/spec/support/event_subscriber.rb +123 -33
- data/spec/support/keyword_struct.rb +26 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/ocsp +1 -0
- data/spec/support/session_registry.rb +52 -0
- data/spec/support/shared/server_selector.rb +13 -1
- data/spec/support/spec_config.rb +60 -13
- data/spec/support/spec_setup.rb +1 -1
- data/spec/support/utils.rb +84 -1
- metadata +1027 -937
- metadata.gz.sig +0 -0
- data/lib/mongo/server_selector/selectable.rb +0 -560
- data/spec/runners/sdam_monitoring.rb +0 -89
- data/spec/support/lite_constraints.rb +0 -141
@@ -19,6 +19,7 @@ module Mongo
|
|
19
19
|
# Defines custom behavior of results in find command with explain.
|
20
20
|
#
|
21
21
|
# @since 2.5.0
|
22
|
+
# @api semiprivate
|
22
23
|
class Result < Operation::Result
|
23
24
|
|
24
25
|
# Get the cursor id.
|
@@ -29,6 +30,7 @@ module Mongo
|
|
29
30
|
# @return [ 0 ] Always 0 because explain doesn't return a cursor.
|
30
31
|
#
|
31
32
|
# @since 2.5.0
|
33
|
+
# @api private
|
32
34
|
def cursor_id
|
33
35
|
0
|
34
36
|
end
|
@@ -41,6 +43,7 @@ module Mongo
|
|
41
43
|
# @return [ Array<BSON::Document> ] The documents.
|
42
44
|
#
|
43
45
|
# @since 2.5.0
|
46
|
+
# @api public
|
44
47
|
def documents
|
45
48
|
reply.documents
|
46
49
|
end
|
@@ -20,6 +20,7 @@ module Mongo
|
|
20
20
|
# Defines custom behavior of results for a query.
|
21
21
|
#
|
22
22
|
# @since 2.1.0
|
23
|
+
# @api semiprivate
|
23
24
|
class Result < Operation::Result
|
24
25
|
include Operation::Result::UseLegacyErrorParser
|
25
26
|
|
@@ -31,6 +32,7 @@ module Mongo
|
|
31
32
|
# @return [ true, false ] If the query was successful.
|
32
33
|
#
|
33
34
|
# @since 2.0.0
|
35
|
+
# @api public
|
34
36
|
def successful?
|
35
37
|
!query_failure?
|
36
38
|
end
|
@@ -19,6 +19,7 @@ module Mongo
|
|
19
19
|
# Defines custom behavior of results in find command.
|
20
20
|
#
|
21
21
|
# @since 2.2.0
|
22
|
+
# @api semiprivate
|
22
23
|
class Result < Operation::Result
|
23
24
|
|
24
25
|
# Get the cursor id.
|
@@ -29,6 +30,7 @@ module Mongo
|
|
29
30
|
# @return [ Integer ] The cursor id.
|
30
31
|
#
|
31
32
|
# @since 2.2.0
|
33
|
+
# @api private
|
32
34
|
def cursor_id
|
33
35
|
cursor_document ? cursor_document[CURSOR_ID] : super
|
34
36
|
end
|
@@ -41,10 +43,21 @@ module Mongo
|
|
41
43
|
# @return [ Array<BSON::Document> ] The documents.
|
42
44
|
#
|
43
45
|
# @since 2.2.0
|
46
|
+
# @api public
|
44
47
|
def documents
|
45
48
|
cursor_document[FIRST_BATCH]
|
46
49
|
end
|
47
50
|
|
51
|
+
# The namespace in which this find command was performed.
|
52
|
+
#
|
53
|
+
# @return [ String ] The namespace, usually in the format
|
54
|
+
# "database.collection".
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
def namespace
|
58
|
+
cursor_document['ns']
|
59
|
+
end
|
60
|
+
|
48
61
|
private
|
49
62
|
|
50
63
|
def cursor_document
|
@@ -19,6 +19,7 @@ module Mongo
|
|
19
19
|
# Defines custom behavior of results for the get more command.
|
20
20
|
#
|
21
21
|
# @since 2.2.0
|
22
|
+
# @api semiprivate
|
22
23
|
class Result < Operation::Result
|
23
24
|
|
24
25
|
# Get the cursor id.
|
@@ -29,6 +30,7 @@ module Mongo
|
|
29
30
|
# @return [ Integer ] The cursor id.
|
30
31
|
#
|
31
32
|
# @since 2.2.0
|
33
|
+
# @api private
|
32
34
|
def cursor_id
|
33
35
|
cursor_document ? cursor_document[CURSOR_ID] : super
|
34
36
|
end
|
@@ -50,6 +52,7 @@ module Mongo
|
|
50
52
|
# @return [ Array<BSON::Document> ] The documents.
|
51
53
|
#
|
52
54
|
# @since 2.2.0
|
55
|
+
# @api public
|
53
56
|
def documents
|
54
57
|
cursor_document[NEXT_BATCH]
|
55
58
|
end
|
@@ -20,6 +20,7 @@ module Mongo
|
|
20
20
|
# listIndexes command.
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
|
+
# @api semiprivate
|
23
24
|
class Result < Operation::Result
|
24
25
|
|
25
26
|
# Get the cursor id for the result.
|
@@ -35,6 +36,7 @@ module Mongo
|
|
35
36
|
# @return [ Integer ] The cursor id.
|
36
37
|
#
|
37
38
|
# @since 2.0.0
|
39
|
+
# @api private
|
38
40
|
def cursor_id
|
39
41
|
cursor_document ? cursor_document[CURSOR_ID] : super
|
40
42
|
end
|
@@ -47,6 +49,7 @@ module Mongo
|
|
47
49
|
# @return [ String ] The namespace.
|
48
50
|
#
|
49
51
|
# @since 2.0.0
|
52
|
+
# @api private
|
50
53
|
def namespace
|
51
54
|
cursor_document ? cursor_document[NAMESPACE] : super
|
52
55
|
end
|
@@ -60,6 +63,7 @@ module Mongo
|
|
60
63
|
# @return [ Array<BSON::Document> ] The documents.
|
61
64
|
#
|
62
65
|
# @since 2.0.0
|
66
|
+
# @api public
|
63
67
|
def documents
|
64
68
|
cursor_document[FIRST_BATCH]
|
65
69
|
end
|
@@ -77,6 +81,7 @@ module Mongo
|
|
77
81
|
# @return [ Result ] Self if successful.
|
78
82
|
#
|
79
83
|
# @since 2.0.0
|
84
|
+
# @api private
|
80
85
|
def validate!
|
81
86
|
!successful? ? raise_operation_failure : self
|
82
87
|
end
|
@@ -19,12 +19,14 @@ module Mongo
|
|
19
19
|
# Defines custom behavior of results for an insert when sent as part of a bulk write.
|
20
20
|
#
|
21
21
|
# @since 2.0.0
|
22
|
+
# @api semiprivate
|
22
23
|
class BulkResult < Operation::Result
|
23
24
|
include Aggregatable
|
24
25
|
|
25
26
|
# Get the ids of the inserted documents.
|
26
27
|
#
|
27
28
|
# @since 2.0.0
|
29
|
+
# @api public
|
28
30
|
attr_reader :inserted_ids
|
29
31
|
|
30
32
|
# Initialize a new result.
|
@@ -39,6 +41,7 @@ module Mongo
|
|
39
41
|
# @param [ Array<Object> ] ids The ids of the inserted documents.
|
40
42
|
#
|
41
43
|
# @since 2.0.0
|
44
|
+
# @api private
|
42
45
|
def initialize(replies, connection_description, ids)
|
43
46
|
@replies = [*replies] if replies
|
44
47
|
@connection_description = connection_description
|
@@ -83,6 +86,7 @@ module Mongo
|
|
83
86
|
# @return [ Integer ] The number of documents inserted.
|
84
87
|
#
|
85
88
|
# @since 2.0.0
|
89
|
+
# @api public
|
86
90
|
def n_inserted
|
87
91
|
written_count
|
88
92
|
end
|
@@ -95,6 +99,7 @@ module Mongo
|
|
95
99
|
# @return [ Object ] The id of the document inserted.
|
96
100
|
#
|
97
101
|
# @since 2.0.0
|
102
|
+
# @api public
|
98
103
|
def inserted_id
|
99
104
|
inserted_ids.first
|
100
105
|
end
|
@@ -22,11 +22,13 @@ module Mongo
|
|
22
22
|
# is optional. It can be added to this class later, if needed.
|
23
23
|
#
|
24
24
|
# @since 2.0.0
|
25
|
+
# @api semiprivate
|
25
26
|
class Result < Operation::Result
|
26
27
|
|
27
28
|
# Get the ids of the inserted documents.
|
28
29
|
#
|
29
30
|
# @since 2.0.0
|
31
|
+
# @api public
|
30
32
|
attr_reader :inserted_ids
|
31
33
|
|
32
34
|
# Initialize a new result.
|
@@ -41,6 +43,7 @@ module Mongo
|
|
41
43
|
# @param [ Array<Object> ] ids The ids of the inserted documents.
|
42
44
|
#
|
43
45
|
# @since 2.0.0
|
46
|
+
# @api private
|
44
47
|
def initialize(replies, connection_description, ids)
|
45
48
|
super(replies, connection_description)
|
46
49
|
@inserted_ids = ids
|
@@ -54,10 +57,12 @@ module Mongo
|
|
54
57
|
# @return [ Object ] The id of the document inserted.
|
55
58
|
#
|
56
59
|
# @since 2.0.0
|
60
|
+
# @api public
|
57
61
|
def inserted_id
|
58
62
|
inserted_ids.first
|
59
63
|
end
|
60
64
|
|
65
|
+
# @api public
|
61
66
|
def bulk_result
|
62
67
|
BulkResult.new(@replies, connection_description, @inserted_ids)
|
63
68
|
end
|
@@ -20,6 +20,7 @@ module Mongo
|
|
20
20
|
# listCollections command.
|
21
21
|
#
|
22
22
|
# @since 2.0.0
|
23
|
+
# @api semiprivate
|
23
24
|
class Result < Operation::Result
|
24
25
|
|
25
26
|
# Get the cursor id for the result.
|
@@ -35,6 +36,7 @@ module Mongo
|
|
35
36
|
# @return [ Integer ] The cursor id.
|
36
37
|
#
|
37
38
|
# @since 2.0.0
|
39
|
+
# @api private
|
38
40
|
def cursor_id
|
39
41
|
cursor_document ? cursor_document[CURSOR_ID] : super
|
40
42
|
end
|
@@ -47,6 +49,7 @@ module Mongo
|
|
47
49
|
# @return [ String ] The namespace.
|
48
50
|
#
|
49
51
|
# @since 2.0.0
|
52
|
+
# @api private
|
50
53
|
def namespace
|
51
54
|
cursor_document ? cursor_document[NAMESPACE] : super
|
52
55
|
end
|
@@ -60,6 +63,7 @@ module Mongo
|
|
60
63
|
# @return [ Array<BSON::Document> ] The documents.
|
61
64
|
#
|
62
65
|
# @since 2.0.0
|
66
|
+
# @api public
|
63
67
|
def documents
|
64
68
|
cursor_document[FIRST_BATCH]
|
65
69
|
end
|
@@ -73,6 +77,7 @@ module Mongo
|
|
73
77
|
# @return [ Result ] Self if successful.
|
74
78
|
#
|
75
79
|
# @since 2.0.0
|
80
|
+
# @api private
|
76
81
|
def validate!
|
77
82
|
if successful?
|
78
83
|
self
|
@@ -19,21 +19,25 @@ module Mongo
|
|
19
19
|
# Defines custom behavior of results for a map reduce operation.
|
20
20
|
#
|
21
21
|
# @since 2.0.0
|
22
|
+
# @api semiprivate
|
22
23
|
class Result < Operation::Result
|
23
24
|
|
24
25
|
# The counts field for the map/reduce.
|
25
26
|
#
|
26
27
|
# @since 2.0.0
|
28
|
+
# @api private
|
27
29
|
COUNTS = 'counts'.freeze
|
28
30
|
|
29
31
|
# The field name for a result without a cursor.
|
30
32
|
#
|
31
33
|
# @since 2.0.0
|
34
|
+
# @api private
|
32
35
|
RESULTS = 'results'.freeze
|
33
36
|
|
34
37
|
# The time the operation took constant.
|
35
38
|
#
|
36
39
|
# @since 2.0.0
|
40
|
+
# @api private
|
37
41
|
TIME = 'timeMillis'.freeze
|
38
42
|
|
39
43
|
# Gets the map/reduce counts from the reply.
|
@@ -44,6 +48,7 @@ module Mongo
|
|
44
48
|
# @return [ Hash ] A hash of the result counts.
|
45
49
|
#
|
46
50
|
# @since 2.0.0
|
51
|
+
# @api public
|
47
52
|
def counts
|
48
53
|
reply.documents[0][COUNTS]
|
49
54
|
end
|
@@ -56,6 +61,7 @@ module Mongo
|
|
56
61
|
# @return [ Array<BSON::Document> ] The documents.
|
57
62
|
#
|
58
63
|
# @since 2.0.0
|
64
|
+
# @api public
|
59
65
|
def documents
|
60
66
|
reply.documents[0][RESULTS] || reply.documents[0][RESULT]
|
61
67
|
end
|
@@ -72,6 +78,7 @@ module Mongo
|
|
72
78
|
# @return [ true, false ] If the command was successful.
|
73
79
|
#
|
74
80
|
# @since 2.0.0
|
81
|
+
# @api public
|
75
82
|
def successful?
|
76
83
|
!documents.nil?
|
77
84
|
end
|
@@ -84,6 +91,7 @@ module Mongo
|
|
84
91
|
# @return [ Integer ] The executing time in milliseconds.
|
85
92
|
#
|
86
93
|
# @since 2.0.0
|
94
|
+
# @api public
|
87
95
|
def time
|
88
96
|
reply.documents[0][TIME]
|
89
97
|
end
|
@@ -102,6 +110,7 @@ module Mongo
|
|
102
110
|
# @return [ Result ] The result if verification passed.
|
103
111
|
#
|
104
112
|
# @since 2.0.0
|
113
|
+
# @api private
|
105
114
|
def validate!
|
106
115
|
documents.nil? ? raise_operation_failure : self
|
107
116
|
end
|
@@ -114,6 +123,7 @@ module Mongo
|
|
114
123
|
# @return [ Integer ] Always 0 because map reduce doesn't return a cursor.
|
115
124
|
#
|
116
125
|
# @since 2.5.0
|
126
|
+
# @api private
|
117
127
|
def cursor_id
|
118
128
|
0
|
119
129
|
end
|
@@ -19,11 +19,13 @@ module Mongo
|
|
19
19
|
# Defines custom behavior of results in a parallel scan.
|
20
20
|
#
|
21
21
|
# @since 2.0.0
|
22
|
+
# @api semiprivate
|
22
23
|
class Result < Operation::Result
|
23
24
|
|
24
25
|
# The name of the cursors field in the result.
|
25
26
|
#
|
26
27
|
# @since 2.0.0
|
28
|
+
# @api private
|
27
29
|
CURSORS = 'cursors'.freeze
|
28
30
|
|
29
31
|
# Get all the cursor ids from the result.
|
@@ -34,6 +36,7 @@ module Mongo
|
|
34
36
|
# @return [ Array<Integer> ] The cursor ids.
|
35
37
|
#
|
36
38
|
# @since 2.0.0
|
39
|
+
# @api private
|
37
40
|
def cursor_ids
|
38
41
|
documents.map {|doc| doc[CURSOR][CURSOR_ID]}
|
39
42
|
end
|
@@ -46,6 +49,7 @@ module Mongo
|
|
46
49
|
# @return [ Array<BSON::Document> ] The documents.
|
47
50
|
#
|
48
51
|
# @since 2.0.0
|
52
|
+
# @api public
|
49
53
|
def documents
|
50
54
|
reply.documents[0][CURSORS]
|
51
55
|
end
|
@@ -27,6 +27,7 @@ module Mongo
|
|
27
27
|
# produce a reply (in which case it is assumed to have succeeded).
|
28
28
|
#
|
29
29
|
# @since 2.0.0
|
30
|
+
# @api semiprivate
|
30
31
|
class Result
|
31
32
|
extend Forwardable
|
32
33
|
include Enumerable
|
@@ -34,41 +35,49 @@ module Mongo
|
|
34
35
|
# The field name for the cursor document in an aggregation.
|
35
36
|
#
|
36
37
|
# @since 2.2.0
|
38
|
+
# @api private
|
37
39
|
CURSOR = 'cursor'.freeze
|
38
40
|
|
39
41
|
# The cursor id field in the cursor document.
|
40
42
|
#
|
41
43
|
# @since 2.2.0
|
44
|
+
# @api private
|
42
45
|
CURSOR_ID = 'id'.freeze
|
43
46
|
|
44
47
|
# The field name for the first batch of a cursor.
|
45
48
|
#
|
46
49
|
# @since 2.2.0
|
50
|
+
# @api private
|
47
51
|
FIRST_BATCH = 'firstBatch'.freeze
|
48
52
|
|
49
53
|
# The field name for the next batch of a cursor.
|
50
54
|
#
|
51
55
|
# @since 2.2.0
|
56
|
+
# @api private
|
52
57
|
NEXT_BATCH = 'nextBatch'.freeze
|
53
58
|
|
54
59
|
# The namespace field in the cursor document.
|
55
60
|
#
|
56
61
|
# @since 2.2.0
|
62
|
+
# @api private
|
57
63
|
NAMESPACE = 'ns'.freeze
|
58
64
|
|
59
65
|
# The number of documents updated in the write.
|
60
66
|
#
|
61
67
|
# @since 2.0.0
|
68
|
+
# @api private
|
62
69
|
N = 'n'.freeze
|
63
70
|
|
64
71
|
# The ok status field in the result.
|
65
72
|
#
|
66
73
|
# @since 2.0.0
|
74
|
+
# @api private
|
67
75
|
OK = 'ok'.freeze
|
68
76
|
|
69
77
|
# The result field constant.
|
70
78
|
#
|
71
79
|
# @since 2.2.0
|
80
|
+
# @api private
|
72
81
|
RESULT = 'result'.freeze
|
73
82
|
|
74
83
|
# Initialize a new result.
|
@@ -106,6 +115,8 @@ module Mongo
|
|
106
115
|
end
|
107
116
|
|
108
117
|
# @return [ Array<Protocol::Message> ] replies The wrapped wire protocol replies.
|
118
|
+
#
|
119
|
+
# @api private
|
109
120
|
attr_reader :replies
|
110
121
|
|
111
122
|
# @return [ Server::Description ] Server description of the server that
|
@@ -129,6 +140,7 @@ module Mongo
|
|
129
140
|
# @return [ true, false ] If the result is acknowledged.
|
130
141
|
#
|
131
142
|
# @since 2.0.0
|
143
|
+
# @api public
|
132
144
|
def acknowledged?
|
133
145
|
!!@replies
|
134
146
|
end
|
@@ -143,6 +155,7 @@ module Mongo
|
|
143
155
|
# @return [ Integer ] The cursor id.
|
144
156
|
#
|
145
157
|
# @since 2.0.0
|
158
|
+
# @api private
|
146
159
|
def cursor_id
|
147
160
|
acknowledged? ? replies.last.cursor_id : 0
|
148
161
|
end
|
@@ -153,6 +166,7 @@ module Mongo
|
|
153
166
|
# @return [ Nil ]
|
154
167
|
#
|
155
168
|
# @since 2.0.0
|
169
|
+
# @api private
|
156
170
|
def namespace
|
157
171
|
nil
|
158
172
|
end
|
@@ -165,6 +179,7 @@ module Mongo
|
|
165
179
|
# @return [ Array<BSON::Document> ] The documents.
|
166
180
|
#
|
167
181
|
# @since 2.0.0
|
182
|
+
# @api public
|
168
183
|
def documents
|
169
184
|
if acknowledged?
|
170
185
|
replies.flat_map(&:documents)
|
@@ -182,9 +197,10 @@ module Mongo
|
|
182
197
|
#
|
183
198
|
# @return [ Enumerator ] The enumerator.
|
184
199
|
#
|
185
|
-
# @since 2.0.0
|
186
|
-
#
|
187
200
|
# @yieldparam [ BSON::Document ] Each document in the result.
|
201
|
+
#
|
202
|
+
# @since 2.0.0
|
203
|
+
# @api public
|
188
204
|
def each(&block)
|
189
205
|
documents.each(&block)
|
190
206
|
end
|
@@ -197,6 +213,7 @@ module Mongo
|
|
197
213
|
# @return [ String ] The inspection.
|
198
214
|
#
|
199
215
|
# @since 2.0.0
|
216
|
+
# @api public
|
200
217
|
def inspect
|
201
218
|
"#<#{self.class.name}:0x#{object_id} documents=#{documents}>"
|
202
219
|
end
|
@@ -209,6 +226,7 @@ module Mongo
|
|
209
226
|
# @return [ Protocol::Message ] The first reply.
|
210
227
|
#
|
211
228
|
# @since 2.0.0
|
229
|
+
# @api private
|
212
230
|
def reply
|
213
231
|
if acknowledged?
|
214
232
|
replies.first
|
@@ -225,6 +243,7 @@ module Mongo
|
|
225
243
|
# @return [ Integer ] The number of documents returned.
|
226
244
|
#
|
227
245
|
# @since 2.0.0
|
246
|
+
# @api public
|
228
247
|
def returned_count
|
229
248
|
if acknowledged?
|
230
249
|
reply.number_returned
|
@@ -245,6 +264,7 @@ module Mongo
|
|
245
264
|
# @return [ true, false ] If the command was successful.
|
246
265
|
#
|
247
266
|
# @since 2.0.0
|
267
|
+
# @api public
|
248
268
|
def successful?
|
249
269
|
return true if !acknowledged?
|
250
270
|
if first_document.has_key?(OK)
|
@@ -262,6 +282,7 @@ module Mongo
|
|
262
282
|
# @return [ true, false ] If the command returned ok.
|
263
283
|
#
|
264
284
|
# @since 2.1.0
|
285
|
+
# @api public
|
265
286
|
def ok?
|
266
287
|
# first_document[OK] is a float, and the server can return
|
267
288
|
# ok as a BSON int32, BSON int64 or a BSON double.
|
@@ -285,6 +306,7 @@ module Mongo
|
|
285
306
|
# @return [ Result ] The result if verification passed.
|
286
307
|
#
|
287
308
|
# @since 2.0.0
|
309
|
+
# @api private
|
288
310
|
def validate!
|
289
311
|
!successful? ? raise_operation_failure : self
|
290
312
|
end
|
@@ -317,12 +339,13 @@ module Mongo
|
|
317
339
|
# error information in this result.
|
318
340
|
#
|
319
341
|
# @raise Error::OperationFailure
|
320
|
-
def raise_operation_failure
|
342
|
+
private def raise_operation_failure
|
321
343
|
raise error
|
322
344
|
end
|
323
|
-
private :raise_operation_failure
|
324
345
|
|
325
346
|
# @return [ TopologyVersion | nil ] The topology version.
|
347
|
+
#
|
348
|
+
# @api private
|
326
349
|
def topology_version
|
327
350
|
unless defined?(@topology_version)
|
328
351
|
@topology_version = first_document['topologyVersion'] &&
|
@@ -339,6 +362,7 @@ module Mongo
|
|
339
362
|
# @return [ Integer ] The number of documents written.
|
340
363
|
#
|
341
364
|
# @since 2.0.0
|
365
|
+
# @api public
|
342
366
|
def written_count
|
343
367
|
if acknowledged?
|
344
368
|
first_document[N] || 0
|
@@ -346,6 +370,8 @@ module Mongo
|
|
346
370
|
0
|
347
371
|
end
|
348
372
|
end
|
373
|
+
|
374
|
+
# @api public
|
349
375
|
alias :n :written_count
|
350
376
|
|
351
377
|
# Get the operation time reported in the server response.
|
@@ -353,9 +379,10 @@ module Mongo
|
|
353
379
|
# @example Get the operation time.
|
354
380
|
# result.operation_time
|
355
381
|
#
|
356
|
-
# @return [ Object ] The operation time value.
|
382
|
+
# @return [ Object | nil ] The operation time value.
|
357
383
|
#
|
358
384
|
# @since 2.5.0
|
385
|
+
# @api public
|
359
386
|
def operation_time
|
360
387
|
first_document && first_document[OPERATION_TIME]
|
361
388
|
end
|
@@ -365,13 +392,14 @@ module Mongo
|
|
365
392
|
# @example Get the cluster time.
|
366
393
|
# result.cluster_time
|
367
394
|
#
|
368
|
-
# @return [
|
395
|
+
# @return [ ClusterTime | nil ] The cluster time document.
|
369
396
|
#
|
370
397
|
# Changed in version 2.9.0: This attribute became an instance of
|
371
398
|
# ClusterTime, which is a subclass of BSON::Document.
|
372
399
|
# Previously it was an instance of BSON::Document.
|
373
400
|
#
|
374
401
|
# @since 2.5.0
|
402
|
+
# @api public
|
375
403
|
def cluster_time
|
376
404
|
first_document && ClusterTime[first_document['$clusterTime']]
|
377
405
|
end
|
@@ -384,6 +412,7 @@ module Mongo
|
|
384
412
|
# @return [ Array ] labels The set of labels.
|
385
413
|
#
|
386
414
|
# @since 2.7.0
|
415
|
+
# @api private
|
387
416
|
def labels
|
388
417
|
@labels ||= parser.labels
|
389
418
|
end
|