mongo 2.13.3 → 2.14.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mongo/address/ipv4.rb +1 -1
  4. data/lib/mongo/address/ipv6.rb +1 -1
  5. data/lib/mongo/address.rb +1 -1
  6. data/lib/mongo/bulk_write.rb +17 -0
  7. data/lib/mongo/caching_cursor.rb +74 -0
  8. data/lib/mongo/client.rb +47 -8
  9. data/lib/mongo/cluster/topology/single.rb +1 -1
  10. data/lib/mongo/cluster.rb +3 -3
  11. data/lib/mongo/collection/view/aggregation.rb +25 -4
  12. data/lib/mongo/collection/view/builder/find_command.rb +38 -18
  13. data/lib/mongo/collection/view/explainable.rb +27 -8
  14. data/lib/mongo/collection/view/iterable.rb +72 -12
  15. data/lib/mongo/collection/view/readable.rb +12 -2
  16. data/lib/mongo/collection/view/writable.rb +15 -1
  17. data/lib/mongo/collection/view.rb +24 -20
  18. data/lib/mongo/collection.rb +26 -2
  19. data/lib/mongo/crypt/encryption_io.rb +6 -6
  20. data/lib/mongo/cursor.rb +1 -0
  21. data/lib/mongo/database/view.rb +1 -1
  22. data/lib/mongo/database.rb +8 -14
  23. data/lib/mongo/error/invalid_read_concern.rb +28 -0
  24. data/lib/mongo/error/server_certificate_revoked.rb +22 -0
  25. data/lib/mongo/error/unsupported_option.rb +14 -12
  26. data/lib/mongo/error.rb +2 -0
  27. data/lib/mongo/grid/fs_bucket.rb +37 -37
  28. data/lib/mongo/lint.rb +2 -1
  29. data/lib/mongo/logger.rb +3 -3
  30. data/lib/mongo/operation/aggregate/result.rb +9 -8
  31. data/lib/mongo/operation/collections_info/command.rb +0 -5
  32. data/lib/mongo/operation/collections_info/result.rb +3 -16
  33. data/lib/mongo/operation/delete/bulk_result.rb +2 -0
  34. data/lib/mongo/operation/delete/result.rb +3 -0
  35. data/lib/mongo/operation/explain/command.rb +4 -0
  36. data/lib/mongo/operation/explain/legacy.rb +4 -0
  37. data/lib/mongo/operation/explain/op_msg.rb +6 -0
  38. data/lib/mongo/operation/explain/result.rb +3 -0
  39. data/lib/mongo/operation/find/legacy/result.rb +2 -0
  40. data/lib/mongo/operation/find/result.rb +3 -0
  41. data/lib/mongo/operation/get_more/result.rb +3 -0
  42. data/lib/mongo/operation/indexes/result.rb +5 -0
  43. data/lib/mongo/operation/insert/bulk_result.rb +5 -0
  44. data/lib/mongo/operation/insert/result.rb +5 -0
  45. data/lib/mongo/operation/list_collections/result.rb +5 -0
  46. data/lib/mongo/operation/map_reduce/result.rb +10 -0
  47. data/lib/mongo/operation/parallel_scan/command.rb +2 -1
  48. data/lib/mongo/operation/parallel_scan/result.rb +4 -0
  49. data/lib/mongo/operation/result.rb +35 -6
  50. data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
  51. data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
  52. data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
  53. data/lib/mongo/operation/shared/executable.rb +1 -0
  54. data/lib/mongo/operation/shared/idable.rb +2 -1
  55. data/lib/mongo/operation/shared/limited.rb +1 -0
  56. data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
  57. data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
  58. data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
  59. data/lib/mongo/operation/shared/sessions_supported.rb +3 -3
  60. data/lib/mongo/operation/shared/specifiable.rb +1 -0
  61. data/lib/mongo/operation/shared/write.rb +1 -0
  62. data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
  63. data/lib/mongo/operation/update/legacy/result.rb +7 -0
  64. data/lib/mongo/operation/update/result.rb +8 -0
  65. data/lib/mongo/operation/users_info/result.rb +3 -0
  66. data/lib/mongo/operation.rb +2 -0
  67. data/lib/mongo/protocol/msg.rb +2 -2
  68. data/lib/mongo/protocol/query.rb +11 -11
  69. data/lib/mongo/query_cache.rb +242 -0
  70. data/lib/mongo/retryable.rb +8 -1
  71. data/lib/mongo/server/connection_common.rb +2 -2
  72. data/lib/mongo/server/connection_pool.rb +3 -0
  73. data/lib/mongo/server/monitor/connection.rb +3 -3
  74. data/lib/mongo/server/monitor.rb +1 -1
  75. data/lib/mongo/server/pending_connection.rb +2 -2
  76. data/lib/mongo/server/push_monitor.rb +1 -1
  77. data/lib/mongo/server.rb +5 -1
  78. data/lib/mongo/server_selector/base.rb +5 -1
  79. data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
  80. data/lib/mongo/session.rb +3 -0
  81. data/lib/mongo/socket/ocsp_cache.rb +97 -0
  82. data/lib/mongo/socket/ocsp_verifier.rb +368 -0
  83. data/lib/mongo/socket/ssl.rb +45 -24
  84. data/lib/mongo/socket.rb +6 -4
  85. data/lib/mongo/srv/monitor.rb +7 -13
  86. data/lib/mongo/srv/resolver.rb +14 -10
  87. data/lib/mongo/timeout.rb +2 -0
  88. data/lib/mongo/uri/options_mapper.rb +582 -0
  89. data/lib/mongo/uri/srv_protocol.rb +3 -2
  90. data/lib/mongo/uri.rb +21 -390
  91. data/lib/mongo/utils.rb +12 -1
  92. data/lib/mongo/version.rb +1 -1
  93. data/lib/mongo.rb +9 -0
  94. data/spec/NOTES.aws-auth.md +12 -7
  95. data/spec/README.md +56 -1
  96. data/spec/integration/bson_symbol_spec.rb +2 -4
  97. data/spec/integration/bulk_write_spec.rb +48 -0
  98. data/spec/integration/client_authentication_options_spec.rb +55 -28
  99. data/spec/integration/connection_pool_populator_spec.rb +3 -1
  100. data/spec/integration/cursor_reaping_spec.rb +53 -17
  101. data/spec/integration/ocsp_connectivity_spec.rb +26 -0
  102. data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
  103. data/spec/integration/ocsp_verifier_spec.rb +334 -0
  104. data/spec/integration/query_cache_spec.rb +1045 -0
  105. data/spec/integration/query_cache_transactions_spec.rb +179 -0
  106. data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
  107. data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
  108. data/spec/integration/sdam_error_handling_spec.rb +69 -18
  109. data/spec/integration/sdam_events_spec.rb +7 -8
  110. data/spec/integration/server_selection_spec.rb +36 -0
  111. data/spec/integration/srv_monitoring_spec.rb +38 -3
  112. data/spec/integration/srv_spec.rb +56 -0
  113. data/spec/lite_spec_helper.rb +4 -2
  114. data/spec/mongo/address_spec.rb +1 -1
  115. data/spec/mongo/caching_cursor_spec.rb +70 -0
  116. data/spec/mongo/client_construction_spec.rb +54 -1
  117. data/spec/mongo/client_encryption_spec.rb +10 -16
  118. data/spec/mongo/client_spec.rb +40 -0
  119. data/spec/mongo/cluster/topology/single_spec.rb +14 -5
  120. data/spec/mongo/cluster_spec.rb +3 -0
  121. data/spec/mongo/collection/view/explainable_spec.rb +87 -4
  122. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
  123. data/spec/mongo/collection_spec.rb +60 -0
  124. data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
  125. data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
  126. data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
  127. data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
  128. data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
  129. data/spec/mongo/database_spec.rb +44 -64
  130. data/spec/mongo/error/no_server_available_spec.rb +1 -1
  131. data/spec/mongo/index/view_spec.rb +2 -4
  132. data/spec/mongo/logger_spec.rb +13 -11
  133. data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
  134. data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
  135. data/spec/mongo/query_cache_spec.rb +279 -0
  136. data/spec/mongo/server/app_metadata_shared.rb +7 -33
  137. data/spec/mongo/server/connection_pool_spec.rb +7 -3
  138. data/spec/mongo/server/connection_spec.rb +14 -7
  139. data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
  140. data/spec/mongo/socket/ssl_spec.rb +1 -1
  141. data/spec/mongo/socket_spec.rb +1 -1
  142. data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
  143. data/spec/mongo/uri_option_parsing_spec.rb +11 -11
  144. data/spec/mongo/uri_spec.rb +68 -41
  145. data/spec/mongo/utils_spec.rb +39 -0
  146. data/spec/runners/auth.rb +3 -0
  147. data/spec/runners/connection_string.rb +35 -124
  148. data/spec/runners/transactions/operation.rb +2 -13
  149. data/spec/spec_tests/cmap_spec.rb +7 -3
  150. data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
  151. data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
  152. data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
  153. data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
  154. data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
  155. data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
  156. data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
  157. data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
  158. data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
  159. data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
  160. data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
  161. data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
  162. data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
  163. data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
  164. data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
  165. data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
  166. data/spec/spec_tests/uri_options_spec.rb +31 -33
  167. data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
  168. data/spec/support/certificates/atlas-ocsp.crt +41 -0
  169. data/spec/support/client_registry.rb +4 -8
  170. data/spec/support/client_registry_macros.rb +4 -4
  171. data/spec/support/common_shortcuts.rb +45 -0
  172. data/spec/support/constraints.rb +23 -0
  173. data/spec/support/lite_constraints.rb +24 -0
  174. data/spec/support/matchers.rb +16 -0
  175. data/spec/support/ocsp +1 -0
  176. data/spec/support/session_registry.rb +52 -0
  177. data/spec/support/spec_config.rb +22 -12
  178. data/spec/support/spec_setup.rb +38 -48
  179. data/spec/support/utils.rb +19 -1
  180. data.tar.gz.sig +1 -3
  181. metadata +938 -933
  182. metadata.gz.sig +0 -0
  183. data/spec/integration/secondary_reads_spec.rb +0 -102
  184. data/spec/shared/LICENSE +0 -20
  185. data/spec/shared/bin/get-mongodb-download-url +0 -17
  186. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  187. data/spec/shared/lib/mrss/cluster_config.rb +0 -221
  188. data/spec/shared/lib/mrss/constraints.rb +0 -346
  189. data/spec/shared/lib/mrss/docker_runner.rb +0 -265
  190. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  191. data/spec/shared/lib/mrss/server_version_registry.rb +0 -115
  192. data/spec/shared/lib/mrss/spec_organizer.rb +0 -152
  193. data/spec/shared/lib/mrss/utils.rb +0 -15
  194. data/spec/shared/share/Dockerfile.erb +0 -231
  195. data/spec/shared/shlib/distro.sh +0 -73
  196. data/spec/shared/shlib/server.sh +0 -290
  197. data/spec/shared/shlib/set_env.sh +0 -128
@@ -20,23 +20,9 @@ module Mongo
20
20
  # collection.
21
21
  #
22
22
  # @since 2.1.0
23
+ # @api semiprivate
23
24
  class Result < Operation::Result
24
25
 
25
- # Initialize a new result.
26
- #
27
- # @param [ Array<Protocol::Message> | nil ] replies The wire protocol replies, if any.
28
- # @param [ Server::Description ] connection_description
29
- # Server description of the server that performed the operation that
30
- # this result is for.
31
- # @param [ String ] database_name The name of the database that the
32
- # query was sent to.
33
- #
34
- # @api private
35
- def initialize(replies, connection_description, database_name)
36
- super(replies, connection_description)
37
- @database_name = database_name
38
- end
39
-
40
26
  # Get the namespace for the cursor.
41
27
  #
42
28
  # @example Get the namespace.
@@ -45,8 +31,9 @@ module Mongo
45
31
  # @return [ String ] The namespace.
46
32
  #
47
33
  # @since 2.1.0
34
+ # @api private
48
35
  def namespace
49
- "#{@database_name}.#{Database::NAMESPACES}"
36
+ Database::NAMESPACES
50
37
  end
51
38
  end
52
39
  end
@@ -19,6 +19,7 @@ module Mongo
19
19
  # Defines custom behavior of results for a delete when 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
 
@@ -30,6 +31,7 @@ module Mongo
30
31
  # @return [ Integer ] The number of documents deleted.
31
32
  #
32
33
  # @since 2.0.0
34
+ # @api public
33
35
  def n_removed
34
36
  return 0 unless acknowledged?
35
37
  @replies.reduce(0) do |n, reply|
@@ -19,6 +19,7 @@ module Mongo
19
19
  # Defines custom behavior of results for a delete.
20
20
  #
21
21
  # @since 2.0.0
22
+ # @api semiprivate
22
23
  class Result < Operation::Result
23
24
 
24
25
  # Get the number of documents deleted.
@@ -29,10 +30,12 @@ module Mongo
29
30
  # @return [ Integer ] The deleted count.
30
31
  #
31
32
  # @since 2.0.0
33
+ # @api public
32
34
  def deleted_count
33
35
  n
34
36
  end
35
37
 
38
+ # @api public
36
39
  def bulk_result
37
40
  BulkResult.new(@replies, connection_description)
38
41
  end
@@ -30,6 +30,10 @@ module Mongo
30
30
 
31
31
  private
32
32
 
33
+ def selector(connection)
34
+ super.merge(spec[:explain])
35
+ end
36
+
33
37
  def message(connection)
34
38
  Protocol::Query.new(db_name, Database::COMMAND, command(connection), options(connection))
35
39
  end
@@ -29,6 +29,10 @@ module Mongo
29
29
 
30
30
  private
31
31
 
32
+ def selector(connection)
33
+ super.merge(spec[:explain])
34
+ end
35
+
32
36
  def message(connection)
33
37
  Protocol::Query.new(db_name, coll_name, command(connection), options(connection))
34
38
  end
@@ -25,6 +25,12 @@ module Mongo
25
25
  include CausalConsistencySupported
26
26
  include ExecutableTransactionLabel
27
27
  include PolymorphicResult
28
+
29
+ private
30
+
31
+ def selector(connection)
32
+ super.merge(spec[:explain])
33
+ end
28
34
  end
29
35
  end
30
36
  end
@@ -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,6 +43,7 @@ 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
@@ -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
@@ -37,7 +37,8 @@ module Mongo
37
37
  read_concern)
38
38
  end
39
39
  sel[:maxTimeMS] = max_time_ms if max_time_ms
40
- add_read_preference_legacy(sel, connection)
40
+ update_selector_for_read_pref(sel, connection)
41
+ sel
41
42
  end
42
43
 
43
44
  def message(connection)
@@ -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 [ nil | ClusterTime ] The cluster time document.
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
@@ -18,6 +18,7 @@ module Mongo
18
18
  # Custom behavior for operations that support the bypassdocumentvalidation option.
19
19
  #
20
20
  # @since 2.5.2
21
+ # @api private
21
22
  module BypassDocumentValidation
22
23
 
23
24
  private