mongo 2.2.7 → 2.3.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 +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/mongo.rb +1 -1
- 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/address/unix.rb +1 -1
- data/lib/mongo/auth.rb +1 -1
- data/lib/mongo/auth/cr.rb +1 -1
- data/lib/mongo/auth/ldap.rb +1 -1
- data/lib/mongo/auth/roles.rb +1 -1
- data/lib/mongo/auth/user.rb +1 -1
- data/lib/mongo/auth/user/view.rb +5 -5
- data/lib/mongo/auth/x509.rb +1 -1
- data/lib/mongo/bson.rb +1 -1
- data/lib/mongo/bulk_write.rb +4 -4
- data/lib/mongo/bulk_write/combineable.rb +1 -1
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/result.rb +1 -1
- data/lib/mongo/bulk_write/result_combiner.rb +1 -1
- data/lib/mongo/bulk_write/transformable.rb +1 -1
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/validatable.rb +1 -1
- data/lib/mongo/client.rb +2 -2
- data/lib/mongo/cluster.rb +15 -3
- data/lib/mongo/cluster/cursor_reaper.rb +174 -0
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/cluster/topology/replica_set.rb +1 -1
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +1 -1
- data/lib/mongo/collection.rb +5 -4
- data/lib/mongo/collection/view.rb +4 -4
- data/lib/mongo/collection/view/aggregation.rb +2 -2
- data/lib/mongo/collection/view/builder.rb +1 -1
- data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
- data/lib/mongo/collection/view/builder/find_command.rb +1 -1
- data/lib/mongo/collection/view/builder/flags.rb +1 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
- data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/explainable.rb +1 -1
- data/lib/mongo/collection/view/immutable.rb +1 -1
- data/lib/mongo/collection/view/iterable.rb +2 -2
- data/lib/mongo/collection/view/map_reduce.rb +3 -3
- data/lib/mongo/collection/view/readable.rb +23 -6
- data/lib/mongo/collection/view/writable.rb +3 -3
- data/lib/mongo/cursor.rb +50 -7
- data/lib/mongo/cursor/builder.rb +1 -1
- data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
- data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
- data/lib/mongo/database.rb +4 -4
- data/lib/mongo/database/view.rb +2 -2
- data/lib/mongo/dbref.rb +4 -3
- data/lib/mongo/error.rb +1 -1
- data/lib/mongo/error/bulk_write_error.rb +1 -1
- data/lib/mongo/error/closed_stream.rb +1 -1
- data/lib/mongo/error/extra_file_chunk.rb +1 -1
- data/lib/mongo/error/file_not_found.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
- data/lib/mongo/error/invalid_collection_name.rb +1 -1
- data/lib/mongo/error/invalid_database_name.rb +1 -1
- data/lib/mongo/error/invalid_document.rb +1 -1
- data/lib/mongo/error/invalid_file.rb +1 -1
- data/lib/mongo/error/invalid_file_revision.rb +1 -1
- data/lib/mongo/error/invalid_nonce.rb +1 -1
- data/lib/mongo/error/invalid_replacement_document.rb +1 -1
- data/lib/mongo/error/invalid_server_preference.rb +1 -1
- data/lib/mongo/error/invalid_signature.rb +1 -1
- data/lib/mongo/error/invalid_update_document.rb +1 -1
- data/lib/mongo/error/invalid_uri.rb +1 -1
- data/lib/mongo/error/invalid_write_concern.rb +1 -1
- data/lib/mongo/error/max_bson_size.rb +1 -1
- data/lib/mongo/error/max_message_size.rb +1 -1
- data/lib/mongo/error/missing_file_chunk.rb +1 -1
- data/lib/mongo/error/multi_index_drop.rb +1 -1
- data/lib/mongo/error/need_primary_server.rb +1 -1
- data/lib/mongo/error/no_server_available.rb +4 -2
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/error/socket_error.rb +1 -1
- data/lib/mongo/error/socket_timeout_error.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
- data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
- data/lib/mongo/error/unexpected_response.rb +1 -1
- data/lib/mongo/error/unsupported_features.rb +1 -1
- data/lib/mongo/event.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/event/publisher.rb +1 -1
- data/lib/mongo/event/subscriber.rb +1 -1
- data/lib/mongo/grid.rb +1 -1
- data/lib/mongo/grid/file.rb +6 -2
- data/lib/mongo/grid/file/chunk.rb +6 -4
- data/lib/mongo/grid/file/info.rb +7 -3
- data/lib/mongo/grid/fs_bucket.rb +12 -6
- data/lib/mongo/grid/stream.rb +1 -1
- data/lib/mongo/grid/stream/read.rb +2 -4
- data/lib/mongo/grid/stream/write.rb +4 -3
- data/lib/mongo/index.rb +1 -1
- data/lib/mongo/index/view.rb +5 -4
- data/lib/mongo/loggable.rb +1 -1
- data/lib/mongo/logger.rb +1 -1
- data/lib/mongo/monitoring.rb +1 -1
- data/lib/mongo/operation.rb +1 -1
- data/lib/mongo/operation/commands.rb +1 -1
- data/lib/mongo/operation/commands/aggregate.rb +7 -7
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +10 -9
- data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
- data/lib/mongo/operation/commands/command.rb +1 -1
- data/lib/mongo/operation/commands/indexes.rb +12 -11
- data/lib/mongo/operation/commands/list_collections.rb +1 -1
- data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/commands/user_query.rb +11 -10
- data/lib/mongo/operation/commands/users_info.rb +2 -2
- data/lib/mongo/operation/commands/users_info/result.rb +1 -1
- data/lib/mongo/operation/executable.rb +8 -7
- data/lib/mongo/operation/kill_cursors.rb +2 -2
- data/lib/mongo/operation/limited.rb +1 -1
- data/lib/mongo/operation/read.rb +1 -1
- data/lib/mongo/operation/read/get_more.rb +2 -2
- data/lib/mongo/operation/read/query.rb +1 -1
- data/lib/mongo/operation/read/query/result.rb +1 -1
- data/lib/mongo/operation/read_preference.rb +10 -10
- data/lib/mongo/operation/result.rb +1 -1
- data/lib/mongo/operation/specifiable.rb +2 -2
- data/lib/mongo/operation/write.rb +1 -1
- data/lib/mongo/operation/write/bulk.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
- data/lib/mongo/operation/write/bulk/delete.rb +3 -3
- data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/insert.rb +5 -5
- data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/update.rb +3 -3
- data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
- data/lib/mongo/operation/write/command.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +1 -1
- data/lib/mongo/operation/write/command/create_user.rb +1 -1
- data/lib/mongo/operation/write/command/delete.rb +1 -1
- data/lib/mongo/operation/write/command/drop_index.rb +1 -1
- data/lib/mongo/operation/write/command/insert.rb +11 -1
- data/lib/mongo/operation/write/command/remove_user.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -1
- data/lib/mongo/operation/write/command/update_user.rb +1 -1
- data/lib/mongo/operation/write/command/writable.rb +7 -6
- data/lib/mongo/operation/write/create_index.rb +1 -1
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/delete/result.rb +1 -1
- data/lib/mongo/operation/write/drop_index.rb +5 -5
- data/lib/mongo/operation/write/gle.rb +3 -3
- data/lib/mongo/operation/write/idable.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +5 -5
- data/lib/mongo/operation/write/insert/result.rb +1 -1
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/operation/write/update/result.rb +1 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/delete.rb +1 -1
- data/lib/mongo/protocol/get_more.rb +1 -1
- data/lib/mongo/protocol/insert.rb +5 -1
- data/lib/mongo/protocol/kill_cursors.rb +1 -1
- data/lib/mongo/protocol/message.rb +9 -5
- data/lib/mongo/protocol/query.rb +1 -1
- data/lib/mongo/protocol/reply.rb +1 -1
- data/lib/mongo/protocol/serializers.rb +8 -8
- data/lib/mongo/protocol/update.rb +1 -1
- data/lib/mongo/server.rb +40 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +4 -2
- data/lib/mongo/server/connection_pool.rb +1 -1
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/context.rb +3 -1
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server_selector.rb +2 -1
- data/lib/mongo/server_selector/nearest.rb +1 -1
- data/lib/mongo/server_selector/primary.rb +1 -1
- data/lib/mongo/server_selector/primary_preferred.rb +1 -1
- data/lib/mongo/server_selector/secondary.rb +1 -1
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
- data/lib/mongo/server_selector/selectable.rb +12 -7
- data/lib/mongo/socket.rb +1 -1
- data/lib/mongo/socket/ssl.rb +1 -1
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +2 -2
- data/lib/mongo/write_concern/acknowledged.rb +1 -1
- data/lib/mongo/write_concern/normalizable.rb +1 -1
- data/lib/mongo/write_concern/unacknowledged.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/mongo/client_spec.rb +2 -2
- data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
- data/spec/mongo/cluster_spec.rb +36 -5
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
- data/spec/mongo/collection/view/readable_spec.rb +203 -5
- data/spec/mongo/collection/view_spec.rb +10 -0
- data/spec/mongo/collection_spec.rb +64 -18
- data/spec/mongo/cursor_spec.rb +89 -0
- data/spec/mongo/database_spec.rb +79 -13
- data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
- data/spec/mongo/grid/stream/write_spec.rb +63 -12
- data/spec/mongo/index/view_spec.rb +19 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
- data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/commands/command_spec.rb +3 -3
- data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
- data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
- data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
- data/spec/mongo/operation/read/get_more_spec.rb +13 -25
- data/spec/mongo/operation/read/query_spec.rb +26 -30
- data/spec/mongo/operation/read_preference_spec.rb +11 -11
- data/spec/mongo/operation/specifiable_spec.rb +31 -0
- data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
- data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
- data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
- data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
- data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
- data/spec/mongo/operation/write/command/update_spec.rb +24 -32
- data/spec/mongo/operation/write/create_index_spec.rb +4 -4
- data/spec/mongo/operation/write/create_user_spec.rb +3 -3
- data/spec/mongo/operation/write/delete_spec.rb +51 -22
- data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
- data/spec/mongo/operation/write/insert_spec.rb +42 -11
- data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
- data/spec/mongo/operation/write/update_spec.rb +34 -6
- data/spec/mongo/operation/write/update_user_spec.rb +1 -1
- data/spec/mongo/server/connection_spec.rb +22 -14
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/mongo/server_selector/nearest_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_spec.rb +2 -2
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/secondary_spec.rb +3 -3
- data/spec/mongo/server_selector_spec.rb +82 -3
- data/spec/mongo/server_spec.rb +0 -20
- data/spec/support/command_monitoring.rb +1 -1
- data/spec/support/connection_string.rb +1 -1
- data/spec/support/crud.rb +1 -1
- data/spec/support/crud/read.rb +1 -1
- data/spec/support/crud/write.rb +1 -1
- data/spec/support/gridfs.rb +1 -1
- data/spec/support/shared/server_selector.rb +3 -3
- metadata +7 -10
- metadata.gz.sig +0 -0
- data/lib/csasl/csasl.bundle +0 -0
- data/spec/mongo/operation/write/response_spec.rb +0 -85
- data/spec/support/shared/operation.rb +0 -100
data/lib/mongo/collection.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -112,8 +112,7 @@ module Mongo
|
|
112
112
|
#
|
113
113
|
# @since 2.0.0
|
114
114
|
def read_preference
|
115
|
-
@read_preference ||=
|
116
|
-
database.read_preference
|
115
|
+
@read_preference ||= ServerSelector.get(options[:read] || database.read_preference)
|
117
116
|
end
|
118
117
|
|
119
118
|
# Get the write concern on this collection.
|
@@ -269,6 +268,7 @@ module Mongo
|
|
269
268
|
# @option options [ Integer ] :limit The maximum number of documents to count.
|
270
269
|
# @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command to run.
|
271
270
|
# @option options [ Integer ] :skip The number of documents to skip before counting.
|
271
|
+
# @option options [ Hash ] :read The read preference options.
|
272
272
|
#
|
273
273
|
# @return [ Integer ] The document count.
|
274
274
|
#
|
@@ -287,6 +287,7 @@ module Mongo
|
|
287
287
|
# @param [ Hash ] options The distinct command options.
|
288
288
|
#
|
289
289
|
# @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command to run.
|
290
|
+
# @option options [ Hash ] :read The read preference options.
|
290
291
|
#
|
291
292
|
# @return [ Array<Object> ] The list of distinct values.
|
292
293
|
#
|
@@ -343,7 +344,7 @@ module Mongo
|
|
343
344
|
:bypass_document_validation => !!options[:bypass_document_validation],
|
344
345
|
:options => options,
|
345
346
|
:id_generator => client.options[:id_generator]
|
346
|
-
).execute(next_primary
|
347
|
+
).execute(next_primary)
|
347
348
|
end
|
348
349
|
end
|
349
350
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -132,7 +132,7 @@ module Mongo
|
|
132
132
|
def initialize(collection, filter = {}, options = {})
|
133
133
|
validate_doc!(filter)
|
134
134
|
@collection = collection
|
135
|
-
parse_parameters!(BSON::Document.new(filter
|
135
|
+
parse_parameters!(BSON::Document.new(filter), BSON::Document.new(options))
|
136
136
|
end
|
137
137
|
|
138
138
|
# Get a human-readable string representation of +View+.
|
@@ -159,8 +159,8 @@ module Mongo
|
|
159
159
|
def parse_parameters!(filter, options)
|
160
160
|
query = filter.delete(QUERY)
|
161
161
|
modifiers = (filter || {}).merge(options.delete(MODIFIERS) || {})
|
162
|
-
@filter = query || filter
|
163
|
-
@options = Builder::Modifiers.map_driver_options(modifiers).merge!(options)
|
162
|
+
@filter = (query || filter).freeze
|
163
|
+
@options = Builder::Modifiers.map_driver_options(modifiers).merge!(options).freeze
|
164
164
|
end
|
165
165
|
|
166
166
|
def new(options)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -115,7 +115,7 @@ module Mongo
|
|
115
115
|
log_warn(REROUTE)
|
116
116
|
server = cluster.next_primary(false)
|
117
117
|
end
|
118
|
-
initial_query_op.execute(server
|
118
|
+
initial_query_op.execute(server)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -77,7 +77,7 @@ module Mongo
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def send_initial_query(server)
|
80
|
-
initial_query_op(server).execute(server
|
80
|
+
initial_query_op(server).execute(server)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -211,7 +211,7 @@ module Mongo
|
|
211
211
|
log_warn(REROUTE)
|
212
212
|
server = cluster.next_primary(false)
|
213
213
|
end
|
214
|
-
result = initial_query_op.execute(server
|
214
|
+
result = initial_query_op.execute(server)
|
215
215
|
inline? ? result : send_fetch_query(server)
|
216
216
|
end
|
217
217
|
|
@@ -232,7 +232,7 @@ module Mongo
|
|
232
232
|
end
|
233
233
|
|
234
234
|
def send_fetch_query(server)
|
235
|
-
fetch_query_op(server).execute(server
|
235
|
+
fetch_query_op(server).execute(server)
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -120,6 +120,7 @@ module Mongo
|
|
120
120
|
# @option options :limit [ Integer ] Max number of docs to return.
|
121
121
|
# @option options :max_time_ms [ Integer ] The maximum amount of time to allow the
|
122
122
|
# command to run.
|
123
|
+
# @option options [ Hash ] :read The read preference options.
|
123
124
|
#
|
124
125
|
# @return [ Integer ] The document count.
|
125
126
|
#
|
@@ -132,6 +133,7 @@ module Mongo
|
|
132
133
|
cmd[:maxTimeMS] = options[:max_time_ms] if options[:max_time_ms]
|
133
134
|
cmd[:readConcern] = collection.read_concern if collection.read_concern
|
134
135
|
read_with_retry do
|
136
|
+
options = options.merge(read: read) unless options[:read]
|
135
137
|
database.command(cmd, options).n.to_i
|
136
138
|
end
|
137
139
|
end
|
@@ -146,7 +148,7 @@ module Mongo
|
|
146
148
|
#
|
147
149
|
# @option options :max_time_ms [ Integer ] The maximum amount of time to allow the
|
148
150
|
# command to run.
|
149
|
-
# @option options
|
151
|
+
# @option options [ Hash ] :read The read preference options.
|
150
152
|
#
|
151
153
|
# @return [ Array<Object> ] The list of distinct values.
|
152
154
|
#
|
@@ -158,6 +160,7 @@ module Mongo
|
|
158
160
|
cmd[:maxTimeMS] = options[:max_time_ms] if options[:max_time_ms]
|
159
161
|
cmd[:readConcern] = collection.read_concern if collection.read_concern
|
160
162
|
read_with_retry do
|
163
|
+
options = options.merge(read: read) unless options[:read]
|
161
164
|
database.command(cmd, options).first['values']
|
162
165
|
end
|
163
166
|
end
|
@@ -293,7 +296,7 @@ module Mongo
|
|
293
296
|
# @since 2.0.0
|
294
297
|
def read(value = nil)
|
295
298
|
return default_read if value.nil?
|
296
|
-
selector =
|
299
|
+
selector = ServerSelector.get(value)
|
297
300
|
configure(:read, selector)
|
298
301
|
end
|
299
302
|
|
@@ -416,6 +419,20 @@ module Mongo
|
|
416
419
|
configure(:max_time_ms, max)
|
417
420
|
end
|
418
421
|
|
422
|
+
# The type of cursor to use. Can be :tailable or :tailable_await.
|
423
|
+
#
|
424
|
+
# @example Set the cursor type.
|
425
|
+
# view.cursor_type(:tailable)
|
426
|
+
#
|
427
|
+
# @param [ :tailable, :tailable_await ] type The cursor type.
|
428
|
+
#
|
429
|
+
# @return [ :tailable, :tailable_await, View ] Either the cursor type setting or a new +View+.
|
430
|
+
#
|
431
|
+
# @since 2.3.0
|
432
|
+
def cursor_type(type = nil)
|
433
|
+
configure(:cursor_type, type)
|
434
|
+
end
|
435
|
+
|
419
436
|
private
|
420
437
|
|
421
438
|
def default_read
|
@@ -429,19 +446,19 @@ module Mongo
|
|
429
446
|
:db_name => database.name,
|
430
447
|
:cursor_count => cursor_count,
|
431
448
|
:read_concern => collection.read_concern
|
432
|
-
).execute(server
|
449
|
+
).execute(server).cursor_ids.map do |cursor_id|
|
433
450
|
result = if server.features.find_command_enabled?
|
434
451
|
Operation::Commands::GetMore.new({
|
435
452
|
:selector => { :getMore => cursor_id, :collection => collection.name },
|
436
453
|
:db_name => database.name
|
437
|
-
}).execute(server
|
454
|
+
}).execute(server)
|
438
455
|
else
|
439
456
|
Operation::Read::GetMore.new({
|
440
457
|
:to_return => 0,
|
441
458
|
:cursor_id => cursor_id,
|
442
459
|
:db_name => database.name,
|
443
460
|
:coll_name => collection.name
|
444
|
-
}).execute(server
|
461
|
+
}).execute(server)
|
445
462
|
end
|
446
463
|
Cursor.new(self, result, server)
|
447
464
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -191,7 +191,7 @@ module Mongo
|
|
191
191
|
:db_name => collection.database.name,
|
192
192
|
:coll_name => collection.name,
|
193
193
|
:write_concern => collection.write_concern
|
194
|
-
).execute(next_primary
|
194
|
+
).execute(next_primary)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -206,7 +206,7 @@ module Mongo
|
|
206
206
|
:coll_name => collection.name,
|
207
207
|
:write_concern => collection.write_concern,
|
208
208
|
:bypass_document_validation => !!opts[:bypass_document_validation]
|
209
|
-
).execute(next_primary
|
209
|
+
).execute(next_primary)
|
210
210
|
end
|
211
211
|
end
|
212
212
|
end
|
data/lib/mongo/cursor.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2014-
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -57,6 +57,31 @@ module Mongo
|
|
57
57
|
@server = server
|
58
58
|
@initial_result = result
|
59
59
|
@remaining = limit if limited?
|
60
|
+
@cursor_id = result.cursor_id
|
61
|
+
register
|
62
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(result.cursor_id,
|
63
|
+
cluster,
|
64
|
+
kill_cursors_op_spec,
|
65
|
+
server))
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# Finalize the cursor for garbage collection. Schedules this cursor to be included
|
70
|
+
# in a killCursors operation executed by the Cluster's CursorReaper.
|
71
|
+
#
|
72
|
+
# @example Finalize the cursor.
|
73
|
+
# Cursor.finalize(id, cluster, op, server)
|
74
|
+
#
|
75
|
+
# @param [ Integer ] cursor_id The cursor's id.
|
76
|
+
# @param [ Mongo::Cluster ] cluster The cluster associated with this cursor and its server.
|
77
|
+
# @param [ Hash ] op_spec The killCursors operation specification.
|
78
|
+
# @param [ Mongo::Server ] server The server to send the killCursors operation to.
|
79
|
+
#
|
80
|
+
# @return [ Proc ] The Finalizer.
|
81
|
+
#
|
82
|
+
# @since 2.3.0
|
83
|
+
def self.finalize(cursor_id, cluster, op_spec, server)
|
84
|
+
proc { cluster.schedule_kill_cursor(cursor_id, op_spec, server) }
|
60
85
|
end
|
61
86
|
|
62
87
|
# Get a human-readable string representation of +Cursor+.
|
@@ -160,7 +185,7 @@ module Mongo
|
|
160
185
|
|
161
186
|
def get_more
|
162
187
|
read_with_retry do
|
163
|
-
process(get_more_operation.execute(@server
|
188
|
+
process(get_more_operation.execute(@server))
|
164
189
|
end
|
165
190
|
end
|
166
191
|
|
@@ -173,16 +198,25 @@ module Mongo
|
|
173
198
|
end
|
174
199
|
|
175
200
|
def kill_cursors
|
176
|
-
|
177
|
-
|
201
|
+
unregister
|
202
|
+
read_with_one_retry do
|
203
|
+
kill_cursors_operation.execute(@server)
|
178
204
|
end
|
179
205
|
end
|
180
206
|
|
181
207
|
def kill_cursors_operation
|
182
208
|
if @server.features.find_command_enabled?
|
183
|
-
Operation::Commands::Command.new(
|
209
|
+
Operation::Commands::Command.new(kill_cursors_op_spec)
|
210
|
+
else
|
211
|
+
Operation::KillCursors.new(kill_cursors_op_spec)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def kill_cursors_op_spec
|
216
|
+
if @server.features.find_command_enabled?
|
217
|
+
Builder::KillCursorsCommand.new(self).specification
|
184
218
|
else
|
185
|
-
|
219
|
+
Builder::OpKillCursors.new(self).specification
|
186
220
|
end
|
187
221
|
end
|
188
222
|
|
@@ -196,13 +230,22 @@ module Mongo
|
|
196
230
|
|
197
231
|
def process(result)
|
198
232
|
@remaining -= result.returned_count if limited?
|
199
|
-
@cursor_id = result.cursor_id
|
200
233
|
@coll_name ||= result.namespace.sub("#{database.name}.", '') if result.namespace
|
234
|
+
unregister if result.cursor_id == 0
|
235
|
+
@cursor_id = result.cursor_id
|
201
236
|
result.documents
|
202
237
|
end
|
203
238
|
|
204
239
|
def use_limit?
|
205
240
|
limited? && batch_size >= @remaining
|
206
241
|
end
|
242
|
+
|
243
|
+
def register
|
244
|
+
cluster.register_cursor(@cursor_id)
|
245
|
+
end
|
246
|
+
|
247
|
+
def unregister
|
248
|
+
cluster.unregister_cursor(@cursor_id)
|
249
|
+
end
|
207
250
|
end
|
208
251
|
end
|
data/lib/mongo/cursor/builder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2015 MongoDB, Inc.
|
1
|
+
# Copyright (C) 2015-2016 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -56,6 +56,34 @@ module Mongo
|
|
56
56
|
def kill_cursors_command
|
57
57
|
{ :killCursors => collection_name, :cursors => [ cursor.id ] }
|
58
58
|
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
|
62
|
+
# Update a specification's list of cursor ids.
|
63
|
+
#
|
64
|
+
# @example Update a specification's list of cursor ids.
|
65
|
+
# KillCursorsCommand.update_cursors(spec, ids)
|
66
|
+
#
|
67
|
+
# @return [ Hash ] The specification.
|
68
|
+
# @return [ Array ] The ids to update with.
|
69
|
+
#
|
70
|
+
# @since 2.3.0
|
71
|
+
def update_cursors(spec, ids)
|
72
|
+
spec[:selector].merge!(cursors: spec[:selector][:cursors] & ids)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Get the list of cursor ids from a spec generated by this Builder.
|
76
|
+
#
|
77
|
+
# @example Get the list of cursor ids.
|
78
|
+
# KillCursorsCommand.cursors(spec)
|
79
|
+
#
|
80
|
+
# @return [ Hash ] The specification.
|
81
|
+
#
|
82
|
+
# @since 2.3.0
|
83
|
+
def get_cursors_list(spec)
|
84
|
+
spec[:selector][:cursors]
|
85
|
+
end
|
86
|
+
end
|
59
87
|
end
|
60
88
|
end
|
61
89
|
end
|