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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +5 -2
- data.tar.gz.sig +0 -0
- data/Rakefile +2 -2
- data/lib/mongo.rb +2 -1
- data/lib/mongo/address.rb +11 -5
- data/lib/mongo/address/ipv4.rb +6 -1
- data/lib/mongo/auth/cr/conversation.rb +1 -1
- data/lib/mongo/auth/ldap/conversation.rb +1 -1
- data/lib/mongo/auth/scram/conversation.rb +1 -1
- data/lib/mongo/auth/user/view.rb +2 -2
- data/lib/mongo/auth/x509/conversation.rb +1 -1
- data/lib/mongo/bulk_write.rb +12 -9
- data/lib/mongo/bulk_write/transformable.rb +20 -5
- data/lib/mongo/client.rb +11 -11
- data/lib/mongo/cluster.rb +2 -2
- data/lib/mongo/collection.rb +21 -8
- data/lib/mongo/collection/view.rb +1 -0
- data/lib/mongo/collection/view/aggregation.rb +11 -5
- data/lib/mongo/collection/view/iterable.rb +6 -2
- data/lib/mongo/collection/view/map_reduce.rb +39 -5
- data/lib/mongo/collection/view/readable.rb +35 -30
- data/lib/mongo/collection/view/writable.rb +26 -18
- data/lib/mongo/database.rb +12 -2
- data/lib/mongo/database/view.rb +4 -3
- data/lib/mongo/dbref.rb +4 -4
- data/lib/mongo/grid/fs_bucket.rb +8 -1
- data/lib/mongo/grid/stream/read.rb +1 -1
- data/lib/mongo/index.rb +5 -0
- data/lib/mongo/index/view.rb +2 -2
- data/lib/mongo/monitoring/command_log_subscriber.rb +9 -3
- data/lib/mongo/monitoring/event.rb +1 -0
- data/lib/mongo/monitoring/event/command_started.rb +2 -1
- data/lib/mongo/monitoring/event/command_succeeded.rb +6 -3
- data/lib/mongo/monitoring/event/secure.rb +58 -0
- data/lib/mongo/operation.rb +31 -1
- data/lib/mongo/operation/commands/collections_info.rb +2 -0
- data/lib/mongo/operation/commands/collections_info/result.rb +39 -0
- data/lib/mongo/operation/commands/list_indexes/result.rb +2 -1
- data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/read/query.rb +2 -0
- data/lib/mongo/operation/read/query/result.rb +40 -0
- data/lib/mongo/operation/result.rb +13 -1
- data/lib/mongo/operation/write/bulk/delete.rb +2 -2
- data/lib/mongo/operation/write/bulk/update.rb +3 -3
- data/lib/mongo/operation/write/delete.rb +2 -2
- data/lib/mongo/operation/write/update.rb +9 -4
- data/lib/mongo/options.rb +1 -0
- data/lib/mongo/options/redacted.rb +156 -0
- data/lib/mongo/protocol/insert.rb +25 -6
- data/lib/mongo/protocol/query.rb +45 -31
- data/lib/mongo/protocol/reply.rb +29 -6
- data/lib/mongo/protocol/serializers.rb +1 -1
- data/lib/mongo/retryable.rb +83 -0
- data/lib/mongo/server.rb +16 -3
- data/lib/mongo/server/connectable.rb +21 -3
- data/lib/mongo/server/connection.rb +38 -4
- data/lib/mongo/server/connection_pool.rb +12 -0
- data/lib/mongo/server/connection_pool/queue.rb +15 -0
- data/lib/mongo/server/monitor/connection.rb +2 -2
- data/lib/mongo/server_selector.rb +5 -0
- data/lib/mongo/server_selector/selectable.rb +16 -9
- data/lib/mongo/socket.rb +6 -2
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +11 -11
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +10 -10
- data/spec/mongo/client_spec.rb +101 -18
- data/spec/mongo/collection_spec.rb +44 -0
- data/spec/mongo/connection_string_spec.rb +36 -58
- data/spec/mongo/database_spec.rb +20 -0
- data/spec/mongo/grid/fs_bucket_spec.rb +1 -1
- data/spec/mongo/grid/stream/write_spec.rb +2 -2
- data/spec/mongo/monitoring/event/command_started_spec.rb +26 -0
- data/spec/mongo/monitoring/event/command_succeeded_spec.rb +26 -0
- data/spec/mongo/monitoring/event/secure_spec.rb +57 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +0 -16
- data/spec/mongo/operation/commands/command_spec.rb +0 -18
- data/spec/mongo/operation/kill_cursors_spec.rb +0 -16
- data/spec/mongo/operation/read/get_more_spec.rb +0 -16
- data/spec/mongo/operation/read/query_spec.rb +19 -16
- data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -16
- data/spec/mongo/operation/write/bulk/update_spec.rb +6 -6
- data/spec/mongo/operation/write/command/delete_spec.rb +0 -16
- data/spec/mongo/operation/write/command/insert_spec.rb +0 -16
- data/spec/mongo/operation/write/command/update_spec.rb +0 -16
- data/spec/mongo/operation/write/delete_spec.rb +3 -3
- data/spec/mongo/operation/write/update_spec.rb +6 -6
- data/spec/mongo/options/redacted_spec.rb +350 -0
- data/spec/mongo/protocol/query_spec.rb +15 -1
- data/spec/mongo/retryable_spec.rb +147 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +16 -0
- data/spec/mongo/server/connection_pool_spec.rb +32 -0
- data/spec/mongo/server/connection_spec.rb +37 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +24 -59
- data/spec/mongo/server_selection_rtt_spec.rb +37 -57
- data/spec/mongo/server_selection_spec.rb +2 -0
- data/spec/mongo/server_selector/nearest_spec.rb +1 -0
- data/spec/mongo/server_selector/primary_preferred_spec.rb +1 -0
- data/spec/mongo/server_selector/primary_spec.rb +8 -2
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +1 -0
- data/spec/mongo/server_selector/secondary_spec.rb +1 -0
- data/spec/mongo/server_spec.rb +68 -1
- data/spec/mongo/socket/ssl_spec.rb +29 -5
- data/spec/mongo/uri_spec.rb +20 -20
- data/spec/support/crud.rb +7 -1
- data/spec/support/matchers.rb +1 -1
- data/spec/support/shared/server_selector.rb +58 -2
- metadata +20 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2c9b3e878a211c1145f6cbe09912ac0fa3c6463
|
4
|
+
data.tar.gz: d18c8e33629e8915fab3fb76edefb8cc631f65af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6ded8b81178ac9561d5f9a3a8ec83edb31dec5528b8365e83f7d24b1b673e23276c1061956db19879d10feb602dacfeb34bbc7f51e5875fd4593ebfea0aa1c0
|
7
|
+
data.tar.gz: 9431cb7dbb2b2b6a18292f454d84835ddbcee391f2a886bd93d398d3f9190a199f9d7a0f6fc2fc27eb95d32b59d900e6fc09317c2b66ec797fc12a42dabaf87c
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,5 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
|
33
|
-
|
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"
|
data/lib/mongo.rb
CHANGED
@@ -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'
|
data/lib/mongo/address.rb
CHANGED
@@ -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 = {
|
32
|
-
|
33
|
-
|
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 ==
|
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
|
data/lib/mongo/address/ipv4.rb
CHANGED
@@ -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][
|
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
|
data/lib/mongo/auth/user/view.rb
CHANGED
@@ -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
|
-
|
94
|
-
|
93
|
+
user: user,
|
94
|
+
db_name: database.name
|
95
95
|
).execute(next_primary.context)
|
96
96
|
end
|
97
97
|
|
data/lib/mongo/bulk_write.rb
CHANGED
@@ -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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
{
|
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
|
-
{
|
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
|
-
{
|
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
|
-
{
|
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
|
-
{
|
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.
|
data/lib/mongo/client.rb
CHANGED
@@ -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[
|
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[
|
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
|
data/lib/mongo/cluster.rb
CHANGED
@@ -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(
|
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
|
data/lib/mongo/collection.rb
CHANGED
@@ -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][
|
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
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
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.
|
@@ -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
|
-
|
46
|
-
|
47
|
-
|
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(
|
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
|
-
|
39
|
-
|
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?
|