mongo 2.1.0.rc0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +5 -2
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +2 -2
  5. data/lib/mongo.rb +2 -1
  6. data/lib/mongo/address.rb +11 -5
  7. data/lib/mongo/address/ipv4.rb +6 -1
  8. data/lib/mongo/auth/cr/conversation.rb +1 -1
  9. data/lib/mongo/auth/ldap/conversation.rb +1 -1
  10. data/lib/mongo/auth/scram/conversation.rb +1 -1
  11. data/lib/mongo/auth/user/view.rb +2 -2
  12. data/lib/mongo/auth/x509/conversation.rb +1 -1
  13. data/lib/mongo/bulk_write.rb +12 -9
  14. data/lib/mongo/bulk_write/transformable.rb +20 -5
  15. data/lib/mongo/client.rb +11 -11
  16. data/lib/mongo/cluster.rb +2 -2
  17. data/lib/mongo/collection.rb +21 -8
  18. data/lib/mongo/collection/view.rb +1 -0
  19. data/lib/mongo/collection/view/aggregation.rb +11 -5
  20. data/lib/mongo/collection/view/iterable.rb +6 -2
  21. data/lib/mongo/collection/view/map_reduce.rb +39 -5
  22. data/lib/mongo/collection/view/readable.rb +35 -30
  23. data/lib/mongo/collection/view/writable.rb +26 -18
  24. data/lib/mongo/database.rb +12 -2
  25. data/lib/mongo/database/view.rb +4 -3
  26. data/lib/mongo/dbref.rb +4 -4
  27. data/lib/mongo/grid/fs_bucket.rb +8 -1
  28. data/lib/mongo/grid/stream/read.rb +1 -1
  29. data/lib/mongo/index.rb +5 -0
  30. data/lib/mongo/index/view.rb +2 -2
  31. data/lib/mongo/monitoring/command_log_subscriber.rb +9 -3
  32. data/lib/mongo/monitoring/event.rb +1 -0
  33. data/lib/mongo/monitoring/event/command_started.rb +2 -1
  34. data/lib/mongo/monitoring/event/command_succeeded.rb +6 -3
  35. data/lib/mongo/monitoring/event/secure.rb +58 -0
  36. data/lib/mongo/operation.rb +31 -1
  37. data/lib/mongo/operation/commands/collections_info.rb +2 -0
  38. data/lib/mongo/operation/commands/collections_info/result.rb +39 -0
  39. data/lib/mongo/operation/commands/list_indexes/result.rb +2 -1
  40. data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
  41. data/lib/mongo/operation/read/query.rb +2 -0
  42. data/lib/mongo/operation/read/query/result.rb +40 -0
  43. data/lib/mongo/operation/result.rb +13 -1
  44. data/lib/mongo/operation/write/bulk/delete.rb +2 -2
  45. data/lib/mongo/operation/write/bulk/update.rb +3 -3
  46. data/lib/mongo/operation/write/delete.rb +2 -2
  47. data/lib/mongo/operation/write/update.rb +9 -4
  48. data/lib/mongo/options.rb +1 -0
  49. data/lib/mongo/options/redacted.rb +156 -0
  50. data/lib/mongo/protocol/insert.rb +25 -6
  51. data/lib/mongo/protocol/query.rb +45 -31
  52. data/lib/mongo/protocol/reply.rb +29 -6
  53. data/lib/mongo/protocol/serializers.rb +1 -1
  54. data/lib/mongo/retryable.rb +83 -0
  55. data/lib/mongo/server.rb +16 -3
  56. data/lib/mongo/server/connectable.rb +21 -3
  57. data/lib/mongo/server/connection.rb +38 -4
  58. data/lib/mongo/server/connection_pool.rb +12 -0
  59. data/lib/mongo/server/connection_pool/queue.rb +15 -0
  60. data/lib/mongo/server/monitor/connection.rb +2 -2
  61. data/lib/mongo/server_selector.rb +5 -0
  62. data/lib/mongo/server_selector/selectable.rb +16 -9
  63. data/lib/mongo/socket.rb +6 -2
  64. data/lib/mongo/uri.rb +1 -1
  65. data/lib/mongo/version.rb +1 -1
  66. data/spec/mongo/bulk_write/ordered_combiner_spec.rb +11 -11
  67. data/spec/mongo/bulk_write/unordered_combiner_spec.rb +10 -10
  68. data/spec/mongo/client_spec.rb +101 -18
  69. data/spec/mongo/collection_spec.rb +44 -0
  70. data/spec/mongo/connection_string_spec.rb +36 -58
  71. data/spec/mongo/database_spec.rb +20 -0
  72. data/spec/mongo/grid/fs_bucket_spec.rb +1 -1
  73. data/spec/mongo/grid/stream/write_spec.rb +2 -2
  74. data/spec/mongo/monitoring/event/command_started_spec.rb +26 -0
  75. data/spec/mongo/monitoring/event/command_succeeded_spec.rb +26 -0
  76. data/spec/mongo/monitoring/event/secure_spec.rb +57 -0
  77. data/spec/mongo/operation/commands/aggregate_spec.rb +0 -16
  78. data/spec/mongo/operation/commands/command_spec.rb +0 -18
  79. data/spec/mongo/operation/kill_cursors_spec.rb +0 -16
  80. data/spec/mongo/operation/read/get_more_spec.rb +0 -16
  81. data/spec/mongo/operation/read/query_spec.rb +19 -16
  82. data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -16
  83. data/spec/mongo/operation/write/bulk/update_spec.rb +6 -6
  84. data/spec/mongo/operation/write/command/delete_spec.rb +0 -16
  85. data/spec/mongo/operation/write/command/insert_spec.rb +0 -16
  86. data/spec/mongo/operation/write/command/update_spec.rb +0 -16
  87. data/spec/mongo/operation/write/delete_spec.rb +3 -3
  88. data/spec/mongo/operation/write/update_spec.rb +6 -6
  89. data/spec/mongo/options/redacted_spec.rb +350 -0
  90. data/spec/mongo/protocol/query_spec.rb +15 -1
  91. data/spec/mongo/retryable_spec.rb +147 -0
  92. data/spec/mongo/server/connection_pool/queue_spec.rb +16 -0
  93. data/spec/mongo/server/connection_pool_spec.rb +32 -0
  94. data/spec/mongo/server/connection_spec.rb +37 -0
  95. data/spec/mongo/server_discovery_and_monitoring_spec.rb +24 -59
  96. data/spec/mongo/server_selection_rtt_spec.rb +37 -57
  97. data/spec/mongo/server_selection_spec.rb +2 -0
  98. data/spec/mongo/server_selector/nearest_spec.rb +1 -0
  99. data/spec/mongo/server_selector/primary_preferred_spec.rb +1 -0
  100. data/spec/mongo/server_selector/primary_spec.rb +8 -2
  101. data/spec/mongo/server_selector/secondary_preferred_spec.rb +1 -0
  102. data/spec/mongo/server_selector/secondary_spec.rb +1 -0
  103. data/spec/mongo/server_spec.rb +68 -1
  104. data/spec/mongo/socket/ssl_spec.rb +29 -5
  105. data/spec/mongo/uri_spec.rb +20 -20
  106. data/spec/support/crud.rb +7 -1
  107. data/spec/support/matchers.rb +1 -1
  108. data/spec/support/shared/server_selector.rb +58 -2
  109. metadata +20 -5
  110. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a265ed462b59e6b5130e74d96dcd8fd03bd1cf8
4
- data.tar.gz: df80f1545fc13f8cbbbaa41b7b2994a396eea58d
3
+ metadata.gz: d2c9b3e878a211c1145f6cbe09912ac0fa3c6463
4
+ data.tar.gz: d18c8e33629e8915fab3fb76edefb8cc631f65af
5
5
  SHA512:
6
- metadata.gz: f8fda95db660cc8690ebb838e7bc037614b34c67e03cb8a397dc9c467acbc27d2b8b39ff9af9ec396a03d86ab4e818dd4f3a333744e2727b7e0612d7e7069f30
7
- data.tar.gz: 5845e5ca349dea175a1001e696d0df2600578cb7163bd236eefa4700f9492ee247feccbd46f9c2ef5e1400e31050629738820c824da69fe25f70dff4f86b7465
6
+ metadata.gz: a6ded8b81178ac9561d5f9a3a8ec83edb31dec5528b8365e83f7d24b1b673e23276c1061956db19879d10feb602dacfeb34bbc7f51e5875fd4593ebfea0aa1c0
7
+ data.tar.gz: 9431cb7dbb2b2b6a18292f454d84835ddbcee391f2a886bd93d398d3f9190a199f9d7a0f6fc2fc27eb95d32b59d900e6fc09317c2b66ec797fc12a42dabaf87c
@@ -1,2 +1,5 @@
1
- c9*>@NZwL0b�����N;�l;.
2
- v^���I*�y�����6�&n�������(���gP�T����H~�i�}ɉB ���$�}/SP#����W���IHdJ\͗[<C=��q�E[j[���q)0f�ln�������n�{,OuS����ǁ2k,r5c��wFY �?}n����r��(�.�/���8jӏ!���6��6|�d�X�P�i���ېmC��N�v�>���6�B�3޲��7��0�qJ5E�
1
+ "W5c��a�A��S��
2
+ � !~���G 7U`A��K�$�
3
+ pno�c��)o��u�� �$��
4
+ +
5
+ +I#W���l5���̿�:F��D;��#QnG��*OP:b�[Hٲ+�4�}�V�o}�).�kͯDjݦ�U�|) _�P@<a2*��'���N��!��)��ڴ8�dH>
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -29,8 +29,8 @@ namespace :spec do
29
29
  end
30
30
 
31
31
  task :release => :spec do
32
- #system "git tag -a #{Mongo::VERSION} -m 'Tagging release: #{Mongo::VERSION}'"
33
- #system "git push --tags"
32
+ system "git tag -a #{Mongo::VERSION} -m 'Tagging release: #{Mongo::VERSION}'"
33
+ system "git push --tags"
34
34
  system "gem build mongo.gemspec"
35
35
  system "gem push mongo-#{Mongo::VERSION}.gem"
36
36
  system "rm mongo-#{Mongo::VERSION}.gem"
@@ -15,9 +15,11 @@
15
15
  require 'forwardable'
16
16
  require 'bson'
17
17
  require 'openssl'
18
+ require 'mongo/options'
18
19
  require 'mongo/loggable'
19
20
  require 'mongo/monitoring'
20
21
  require 'mongo/logger'
22
+ require 'mongo/retryable'
21
23
  require 'mongo/operation'
22
24
  require 'mongo/error'
23
25
  require 'mongo/event'
@@ -31,7 +33,6 @@ require 'mongo/database'
31
33
  require 'mongo/dbref'
32
34
  require 'mongo/grid'
33
35
  require 'mongo/index'
34
- require 'mongo/options'
35
36
  require 'mongo/protocol'
36
37
  require 'mongo/server'
37
38
  require 'mongo/server_selector'
@@ -28,10 +28,16 @@ module Mongo
28
28
  # Mapping from socket family to resolver class.
29
29
  #
30
30
  # @since 2.0.0
31
- FAMILY_MAP = { ::Socket::PF_UNIX => Unix,
32
- ::Socket::AF_INET6 => IPv6,
33
- ::Socket::AF_INET => IPv4
34
- }
31
+ FAMILY_MAP = {
32
+ ::Socket::PF_UNIX => Unix,
33
+ ::Socket::AF_INET6 => IPv6,
34
+ ::Socket::AF_INET => IPv4
35
+ }.freeze
36
+
37
+ # The localhost constant.
38
+ #
39
+ # @since 2.1.0
40
+ LOCALHOST = 'localhost'.freeze
35
41
 
36
42
  # @return [ String ] seed The seed address.
37
43
  attr_reader :seed
@@ -146,7 +152,7 @@ module Mongo
146
152
  def initialize_resolver!(timeout, ssl_options)
147
153
  return Unix.new(seed.downcase) if seed.downcase =~ Unix::MATCH
148
154
 
149
- family = (host == 'localhost') ? ::Socket::AF_INET : ::Socket::AF_UNSPEC
155
+ family = (host == LOCALHOST) ? ::Socket::AF_INET : ::Socket::AF_UNSPEC
150
156
  error = nil
151
157
  ::Socket.getaddrinfo(host, nil, family, ::Socket::SOCK_STREAM).each do |info|
152
158
  begin
@@ -35,6 +35,11 @@ module Mongo
35
35
  # @since 2.0.0
36
36
  MATCH = Regexp.new('/\./').freeze
37
37
 
38
+ # Split value constant.
39
+ #
40
+ # @since 2.1.0
41
+ SPLIT = ':'.freeze
42
+
38
43
  # Parse an IPv4 address into its host and port.
39
44
  #
40
45
  # @example Parse the address.
@@ -46,7 +51,7 @@ module Mongo
46
51
  #
47
52
  # @since 2.0.0
48
53
  def self.parse(address)
49
- parts = address.split(':')
54
+ parts = address.split(SPLIT)
50
55
  host = parts[0]
51
56
  port = (parts[1] || 27017).to_i
52
57
  [ host, port ]
@@ -111,7 +111,7 @@ module Mongo
111
111
  private
112
112
 
113
113
  def validate!(reply)
114
- raise Unauthorized.new(user) if reply.documents[0]['ok'] != 1
114
+ raise Unauthorized.new(user) if reply.documents[0][Operation::Result::OK] != 1
115
115
  @nonce = reply.documents[0][Auth::NONCE]
116
116
  @reply = reply
117
117
  end
@@ -87,7 +87,7 @@ module Mongo
87
87
  end
88
88
 
89
89
  def validate!(reply)
90
- raise Unauthorized.new(user) if reply.documents[0]['ok'] != 1
90
+ raise Unauthorized.new(user) if reply.documents[0][Operation::Result::OK] != 1
91
91
  @reply = reply
92
92
  end
93
93
  end
@@ -448,7 +448,7 @@ module Mongo
448
448
  end
449
449
 
450
450
  def validate!(reply)
451
- raise Unauthorized.new(user) unless reply.documents[0]['ok'] == 1
451
+ raise Unauthorized.new(user) unless reply.documents[0][Operation::Result::OK] == 1
452
452
  @reply = reply
453
453
  end
454
454
  end
@@ -90,8 +90,8 @@ module Mongo
90
90
  def update(user_or_name, options = {})
91
91
  user = generate(user_or_name, options)
92
92
  Operation::Write::UpdateUser.new(
93
- user: user,
94
- db_name: database.name
93
+ user: user,
94
+ db_name: database.name
95
95
  ).execute(next_primary.context)
96
96
  end
97
97
 
@@ -83,7 +83,7 @@ module Mongo
83
83
  private
84
84
 
85
85
  def validate!(reply)
86
- raise Unauthorized.new(user) if reply.documents[0]['ok'] != 1
86
+ raise Unauthorized.new(user) if reply.documents[0][Operation::Result::OK] != 1
87
87
  @reply = reply
88
88
  end
89
89
  end
@@ -23,6 +23,7 @@ require 'mongo/bulk_write/result_combiner'
23
23
  module Mongo
24
24
  class BulkWrite
25
25
  extend Forwardable
26
+ include Retryable
26
27
 
27
28
  # @return [ Mongo::Collection ] collection The collection.
28
29
  attr_reader :collection
@@ -45,17 +46,19 @@ module Mongo
45
46
  #
46
47
  # @since 2.1.0
47
48
  def execute
48
- server = next_primary
49
49
  operation_id = Monitoring.next_operation_id
50
50
  result_combiner = ResultCombiner.new
51
- operations.each do |operation|
52
- execute_operation(
53
- operation.keys.first,
54
- operation.values.first,
55
- server,
56
- operation_id,
57
- result_combiner
58
- )
51
+ write_with_retry do
52
+ server = next_primary
53
+ operations.each do |operation|
54
+ execute_operation(
55
+ operation.keys.first,
56
+ operation.values.first,
57
+ server,
58
+ operation_id,
59
+ result_combiner
60
+ )
61
+ end
59
62
  end
60
63
  result_combiner.result
61
64
  end
@@ -56,14 +56,14 @@ module Mongo
56
56
  #
57
57
  # @since 2.1.0
58
58
  DELETE_MANY_TRANSFORM = ->(doc){
59
- { q: doc[:filter], limit: 0 }
59
+ { Operation::Q => doc[:filter], Operation::LIMIT => 0 }
60
60
  }
61
61
 
62
62
  # Proc to transform delete one ops.
63
63
  #
64
64
  # @since 2.1.0
65
65
  DELETE_ONE_TRANSFORM = ->(doc){
66
- { q: doc[:filter], limit: 1 }
66
+ { Operation::Q => doc[:filter], Operation::LIMIT => 1 }
67
67
  }
68
68
 
69
69
  # Proc to transform insert one ops.
@@ -77,21 +77,36 @@ module Mongo
77
77
  #
78
78
  # @since 2.1.0
79
79
  REPLACE_ONE_TRANSFORM = ->(doc){
80
- { q: doc[:filter], u: doc[:replacement], multi: false, upsert: doc.fetch(:upsert, false) }
80
+ {
81
+ Operation::Q => doc[:filter],
82
+ Operation::U => doc[:replacement],
83
+ Operation::MULTI => false,
84
+ Operation::UPSERT => doc.fetch(:upsert, false)
85
+ }
81
86
  }
82
87
 
83
88
  # Proc to transform update many ops.
84
89
  #
85
90
  # @since 2.1.0
86
91
  UPDATE_MANY_TRANSFORM = ->(doc){
87
- { q: doc[:filter], u: doc[:update], multi: true, upsert: doc.fetch(:upsert, false) }
92
+ {
93
+ Operation::Q => doc[:filter],
94
+ Operation::U => doc[:update],
95
+ Operation::MULTI => true,
96
+ Operation::UPSERT => doc.fetch(:upsert, false)
97
+ }
88
98
  }
89
99
 
90
100
  # Proc to transform update one ops.
91
101
  #
92
102
  # @since 2.1.0
93
103
  UPDATE_ONE_TRANSFORM = ->(doc){
94
- { q: doc[:filter], u: doc[:update], multi: false, upsert: doc.fetch(:upsert, false) }
104
+ {
105
+ Operation::Q => doc[:filter],
106
+ Operation::U => doc[:update],
107
+ Operation::MULTI => false,
108
+ Operation::UPSERT => doc.fetch(:upsert, false)
109
+ }
95
110
  }
96
111
 
97
112
  # Document mappers from the bulk api input into proper commands.
@@ -153,7 +153,7 @@ module Mongo
153
153
  # logs at the default 250 characters.
154
154
  #
155
155
  # @since 2.0.0
156
- def initialize(addresses_or_uri, options = {})
156
+ def initialize(addresses_or_uri, options = Options::Redacted.new)
157
157
  @monitoring = Monitoring.new(options)
158
158
  if addresses_or_uri.is_a?(::String)
159
159
  create_from_uri(addresses_or_uri, options)
@@ -185,7 +185,7 @@ module Mongo
185
185
  #
186
186
  # @since 2.0.0
187
187
  def read_preference
188
- @read_preference ||= ServerSelector.get((options[:read] || {}).merge(options))
188
+ @read_preference ||= ServerSelector.get(Options::Redacted.new(options[:read] || {}).merge(options))
189
189
  end
190
190
 
191
191
  # Use the database with the provided name. This will switch the current
@@ -215,9 +215,9 @@ module Mongo
215
215
  # @return [ Mongo::Client ] A new client instance.
216
216
  #
217
217
  # @since 2.0.0
218
- def with(new_options = {})
218
+ def with(new_options = Options::Redacted.new)
219
219
  clone.tap do |client|
220
- opts = new_options || {}
220
+ opts = Options::Redacted.new(new_options) || Options::Redacted.new
221
221
  client.options.update(opts)
222
222
  Database.create(client)
223
223
  # We can't use the same cluster if some options that would affect it
@@ -274,7 +274,7 @@ module Mongo
274
274
  #
275
275
  # @since 2.0.5
276
276
  def database_names
277
- list_databases.collect{ |info| info['name'] }
277
+ list_databases.collect{ |info| info[Database::NAME] }
278
278
  end
279
279
 
280
280
  # Get info for each database.
@@ -286,20 +286,20 @@ module Mongo
286
286
  #
287
287
  # @since 2.0.5
288
288
  def list_databases
289
- use(Database::ADMIN).command(listDatabases: 1).first['databases']
289
+ use(Database::ADMIN).command(listDatabases: 1).first[Database::DATABASES]
290
290
  end
291
291
 
292
292
  private
293
293
 
294
- def create_from_addresses(addresses, opts = {})
295
- @options = Database::DEFAULT_OPTIONS.merge(opts).freeze
294
+ def create_from_addresses(addresses, opts = Options::Redacted.new)
295
+ @options = Options::Redacted.new(Database::DEFAULT_OPTIONS.merge(opts)).freeze
296
296
  @cluster = Cluster.new(addresses, @monitoring, options)
297
297
  @database = Database.new(self, options[:database], options)
298
298
  end
299
299
 
300
- def create_from_uri(connection_string, opts = {})
300
+ def create_from_uri(connection_string, opts = Options::Redacted.new)
301
301
  uri = URI.new(connection_string, opts)
302
- @options = Database::DEFAULT_OPTIONS.merge(uri.client_options.merge(opts)).freeze
302
+ @options = Options::Redacted.new(Database::DEFAULT_OPTIONS.merge(uri.client_options.merge(opts))).freeze
303
303
  @cluster = Cluster.new(uri.servers, @monitoring, options)
304
304
  @database = Database.new(self, options[:database], options)
305
305
  end
@@ -314,7 +314,7 @@ module Mongo
314
314
 
315
315
  def cluster_modifying?(new_options)
316
316
  cluster_options = new_options.reject do |name|
317
- CRUD_OPTIONS.include?(name)
317
+ CRUD_OPTIONS.include?(name.to_sym)
318
318
  end
319
319
  cluster_options.any? do |name, value|
320
320
  options[name] != value
@@ -88,7 +88,7 @@ module Mongo
88
88
  # @param [ Hash ] options The options.
89
89
  #
90
90
  # @since 2.0.0
91
- def initialize(seeds, monitoring, options = {})
91
+ def initialize(seeds, monitoring, options = Options::Redacted.new)
92
92
  @addresses = []
93
93
  @servers = []
94
94
  @monitoring = monitoring
@@ -125,7 +125,7 @@ module Mongo
125
125
  #
126
126
  # @since 2.0.0
127
127
  def next_primary
128
- ServerSelector.get({ mode: :primary }.merge(options)).select_server(self)
128
+ ServerSelector.get(ServerSelector::PRIMARY.merge(options)).select_server(self)
129
129
  end
130
130
 
131
131
  # Elect a primary server from the description that has just changed to a
@@ -23,6 +23,17 @@ module Mongo
23
23
  # @since 2.0.0
24
24
  class Collection
25
25
  extend Forwardable
26
+ include Retryable
27
+
28
+ # The capped option.
29
+ #
30
+ # @since 2.1.0
31
+ CAPPED = 'capped'.freeze
32
+
33
+ # The ns field constant.
34
+ #
35
+ # @since 2.1.0
36
+ NS = 'ns'.freeze
26
37
 
27
38
  # @return [ Mongo::Database ] The database the collection resides in.
28
39
  attr_reader :database
@@ -136,7 +147,7 @@ module Mongo
136
147
  #
137
148
  # @since 2.0.0
138
149
  def capped?
139
- database.command(:collstats => name).documents[0]['capped']
150
+ database.command(:collstats => name).documents[0][CAPPED]
140
151
  end
141
152
 
142
153
  # Force the collection to be created in the database.
@@ -309,13 +320,15 @@ module Mongo
309
320
  #
310
321
  # @since 2.0.0
311
322
  def insert_one(document, options = {})
312
- Operation::Write::Insert.new(
313
- :documents => [ document ],
314
- :db_name => database.name,
315
- :coll_name => name,
316
- :write_concern => write_concern,
317
- :options => options
318
- ).execute(next_primary.context)
323
+ write_with_retry do
324
+ Operation::Write::Insert.new(
325
+ :documents => [ document ],
326
+ :db_name => database.name,
327
+ :coll_name => name,
328
+ :write_concern => write_concern,
329
+ :options => options
330
+ ).execute(next_primary.context)
331
+ end
319
332
  end
320
333
 
321
334
  # Insert the provided documents into the collection.
@@ -44,6 +44,7 @@ module Mongo
44
44
  include Immutable
45
45
  include Iterable
46
46
  include Readable
47
+ include Retryable
47
48
  include Explainable
48
49
  include Writable
49
50
 
@@ -26,6 +26,7 @@ module Mongo
26
26
  include Iterable
27
27
  include Explainable
28
28
  include Loggable
29
+ include Retryable
29
30
 
30
31
  # @return [ View ] view The collection view.
31
32
  attr_reader :view
@@ -42,10 +43,15 @@ module Mongo
42
43
  #
43
44
  # @since 2.1.0
44
45
  OPTIONS_MAP = {
45
- :allow_disk_use => :allowDiskUse,
46
- :max_time_ms => :maxTimeMS,
47
- :explain => :explain
48
- }
46
+ :allow_disk_use => :allowDiskUse,
47
+ :max_time_ms => :maxTimeMS,
48
+ :explain => :explain
49
+ }.freeze
50
+
51
+ # The reroute message.
52
+ #
53
+ # @since 2.1.0
54
+ REROUTE = 'Rerouting the Aggregation operation to the primary server.'.freeze
49
55
 
50
56
  # Set to true if disk usage is allowed during the aggregation.
51
57
  #
@@ -143,7 +149,7 @@ module Mongo
143
149
 
144
150
  def send_initial_query(server)
145
151
  unless valid_server?(server)
146
- log_warn('Rerouting the Aggregation operation to the primary server.')
152
+ log_warn(REROUTE)
147
153
  server = cluster.next_primary
148
154
  end
149
155
  initial_query_op.execute(server.context)
@@ -35,8 +35,12 @@ module Mongo
35
35
  #
36
36
  # @yieldparam [ Hash ] Each matching document.
37
37
  def each
38
- server = read.select_server(cluster)
39
- @cursor = Cursor.new(view, send_initial_query(server), server)
38
+ @cursor = nil
39
+ read_with_retry do
40
+ server = read.select_server(cluster)
41
+ result = send_initial_query(server)
42
+ @cursor = Cursor.new(view, result, server)
43
+ end
40
44
  @cursor.each do |doc|
41
45
  yield doc
42
46
  end if block_given?