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
@@ -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.
|
@@ -50,13 +50,13 @@ module Mongo
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
def execute_write_command(
|
53
|
+
def execute_write_command(server)
|
54
54
|
command_spec = spec.merge(:documents => ensure_ids(documents))
|
55
|
-
Result.new(Command::Insert.new(command_spec).execute(
|
55
|
+
Result.new(Command::Insert.new(command_spec).execute(server), @ids).validate!
|
56
56
|
end
|
57
57
|
|
58
|
-
def execute_message(
|
59
|
-
|
58
|
+
def execute_message(server)
|
59
|
+
server.with_connection do |connection|
|
60
60
|
Result.new(connection.dispatch([ message, gle ].compact), @ids).validate!
|
61
61
|
end
|
62
62
|
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.
|
@@ -26,26 +26,27 @@ module Mongo
|
|
26
26
|
# Execute the operation.
|
27
27
|
#
|
28
28
|
# @example Execute the operation.
|
29
|
-
# operation.execute(
|
29
|
+
# operation.execute(server)
|
30
30
|
#
|
31
|
-
# @param [ Mongo::Server
|
31
|
+
# @param [ Mongo::Server ] server The server to send this operation to.
|
32
32
|
#
|
33
33
|
# @return [ Result ] The operation result.
|
34
34
|
#
|
35
35
|
# @since 2.1.0
|
36
|
-
def execute(
|
37
|
-
if
|
38
|
-
|
36
|
+
def execute(server)
|
37
|
+
if !server.features.write_command_enabled? ||
|
38
|
+
(write_concern && write_concern.get_last_error.nil?)
|
39
|
+
execute_message(server)
|
39
40
|
else
|
40
|
-
|
41
|
+
execute_write_command(server)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
45
|
private
|
45
46
|
|
46
|
-
def execute_write_command(
|
47
|
+
def execute_write_command(server)
|
47
48
|
result_class = self.class.const_defined?(:Result, false) ? self.class::Result : Result
|
48
|
-
result_class.new(write_command_op.execute(
|
49
|
+
result_class.new(write_command_op.execute(server)).validate!
|
49
50
|
end
|
50
51
|
end
|
51
52
|
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.
|
@@ -38,7 +38,7 @@ module Mongo
|
|
38
38
|
# @param value [ Array<Symbol> ] Array of flags to encode
|
39
39
|
#
|
40
40
|
# @return [ String ] Buffer that received the serialized vector
|
41
|
-
def serialize(buffer, value)
|
41
|
+
def serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
|
42
42
|
bits = 0
|
43
43
|
value.each { |flag| bits |= @masks[flag] }
|
44
44
|
buffer.put_int32(bits)
|
@@ -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.
|
@@ -75,6 +75,10 @@ module Mongo
|
|
75
75
|
|
76
76
|
private
|
77
77
|
|
78
|
+
def validating_keys?
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
78
82
|
attr_reader :upconverter
|
79
83
|
|
80
84
|
# The operation code required to specify an Insert message.
|
@@ -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.
|
@@ -199,16 +199,16 @@ module Mongo
|
|
199
199
|
if field[:multi]
|
200
200
|
value.each do |item|
|
201
201
|
if field[:type].respond_to?(:size_limited?)
|
202
|
-
field[:type].serialize(buffer, item, max_bson_size)
|
202
|
+
field[:type].serialize(buffer, item, max_bson_size, validating_keys?)
|
203
203
|
else
|
204
|
-
field[:type].serialize(buffer, item)
|
204
|
+
field[:type].serialize(buffer, item, validating_keys?)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
else
|
208
208
|
if field[:type].respond_to?(:size_limited?)
|
209
|
-
field[:type].serialize(buffer, value, max_bson_size)
|
209
|
+
field[:type].serialize(buffer, value, max_bson_size, validating_keys?)
|
210
210
|
else
|
211
|
-
field[:type].serialize(buffer, value)
|
211
|
+
field[:type].serialize(buffer, value, validating_keys?)
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
@@ -292,6 +292,10 @@ module Mongo
|
|
292
292
|
field[:type].deserialize(io)
|
293
293
|
)
|
294
294
|
end
|
295
|
+
|
296
|
+
def validating_keys?
|
297
|
+
@options[:validating_keys] if @options
|
298
|
+
end
|
295
299
|
end
|
296
300
|
end
|
297
301
|
end
|
data/lib/mongo/protocol/query.rb
CHANGED
data/lib/mongo/protocol/reply.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.
|
@@ -50,7 +50,7 @@ module Mongo
|
|
50
50
|
# @param value [ String ] Header value to be serialized.
|
51
51
|
#
|
52
52
|
# @return [ String ] Buffer with serialized value.
|
53
|
-
def self.serialize(buffer, value)
|
53
|
+
def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
|
54
54
|
buffer.put_bytes(value.pack(HEADER_PACK))
|
55
55
|
end
|
56
56
|
|
@@ -76,7 +76,7 @@ module Mongo
|
|
76
76
|
# @param value [ String ] The string to be serialized.
|
77
77
|
#
|
78
78
|
# @return [ String ] Buffer with serialized value.
|
79
|
-
def self.serialize(buffer, value)
|
79
|
+
def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
|
80
80
|
buffer.put_cstring(value)
|
81
81
|
end
|
82
82
|
end
|
@@ -92,7 +92,7 @@ module Mongo
|
|
92
92
|
# @param value [ Fixnum ] Ignored value.
|
93
93
|
#
|
94
94
|
# @return [ String ] Buffer with serialized value.
|
95
|
-
def self.serialize(buffer, value)
|
95
|
+
def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
|
96
96
|
buffer.put_int32(ZERO)
|
97
97
|
end
|
98
98
|
end
|
@@ -108,7 +108,7 @@ module Mongo
|
|
108
108
|
# @param value [ Fixnum ] 32-bit integer to be serialized.
|
109
109
|
#
|
110
110
|
# @return [String] Buffer with serialized value.
|
111
|
-
def self.serialize(buffer, value)
|
111
|
+
def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
|
112
112
|
buffer.put_int32(value)
|
113
113
|
end
|
114
114
|
|
@@ -133,7 +133,7 @@ module Mongo
|
|
133
133
|
# @param value [ Fixnum ] 64-bit integer to be serialized.
|
134
134
|
#
|
135
135
|
# @return [ String ] Buffer with serialized value.
|
136
|
-
def self.serialize(buffer, value)
|
136
|
+
def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
|
137
137
|
buffer.put_int64(value)
|
138
138
|
end
|
139
139
|
|
@@ -158,9 +158,9 @@ module Mongo
|
|
158
158
|
# @param value [ Hash ] Document to serialize as BSON.
|
159
159
|
#
|
160
160
|
# @return [ String ] Buffer with serialized value.
|
161
|
-
def self.serialize(buffer, value, max_bson_size = nil)
|
161
|
+
def self.serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?)
|
162
162
|
start_size = buffer.length
|
163
|
-
value.to_bson(buffer)
|
163
|
+
value.to_bson(buffer, validating_keys)
|
164
164
|
if max_bson_size && buffer.length - start_size > max_bson_size
|
165
165
|
raise Error::MaxBSONSize.new(max_bson_size)
|
166
166
|
end
|
data/lib/mongo/server.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.
|
@@ -63,7 +63,8 @@ module Mongo
|
|
63
63
|
:replica_set_name,
|
64
64
|
:secondary?,
|
65
65
|
:standalone?,
|
66
|
-
:unknown
|
66
|
+
:unknown?,
|
67
|
+
:unknown!
|
67
68
|
|
68
69
|
# Is this server equal to another?
|
69
70
|
#
|
@@ -88,6 +89,8 @@ module Mongo
|
|
88
89
|
# @return [ Mongo::Server::Context ] context The server context.
|
89
90
|
#
|
90
91
|
# @since 2.0.0
|
92
|
+
#
|
93
|
+
# @deprecated Will be removed in version 3.0
|
91
94
|
def context
|
92
95
|
Context.new(self)
|
93
96
|
end
|
@@ -102,7 +105,7 @@ module Mongo
|
|
102
105
|
#
|
103
106
|
# @since 2.1.0
|
104
107
|
def connectable?
|
105
|
-
|
108
|
+
with_connection do |connection|
|
106
109
|
connection.connectable?
|
107
110
|
end
|
108
111
|
end
|
@@ -212,5 +215,39 @@ module Mongo
|
|
212
215
|
def reconnect!
|
213
216
|
monitor.restart! and true
|
214
217
|
end
|
218
|
+
|
219
|
+
# Execute a block of code with a connection, that is checked out of the
|
220
|
+
# server's pool and then checked back in.
|
221
|
+
#
|
222
|
+
# @example Send a message with the connection.
|
223
|
+
# server.with_connection do |connection|
|
224
|
+
# connection.dispatch([ command ])
|
225
|
+
# end
|
226
|
+
#
|
227
|
+
# @return [ Object ] The result of the block execution.
|
228
|
+
#
|
229
|
+
# @since 2.3.0
|
230
|
+
def with_connection(&block)
|
231
|
+
pool.with_connection(&block)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Handle authentication failure.
|
235
|
+
#
|
236
|
+
# @example Handle possible authentication failure.
|
237
|
+
# server.handle_auth_failure! do
|
238
|
+
# Auth.get(user).login(self)
|
239
|
+
# end
|
240
|
+
#
|
241
|
+
# @raise [ Auth::Unauthorized ] If the authentication failed.
|
242
|
+
#
|
243
|
+
# @return [ Object ] The result of the block execution.
|
244
|
+
#
|
245
|
+
# @since 2.3.0
|
246
|
+
def handle_auth_failure!
|
247
|
+
yield
|
248
|
+
rescue Auth::Unauthorized
|
249
|
+
unknown!
|
250
|
+
raise
|
251
|
+
end
|
215
252
|
end
|
216
253
|
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.
|
@@ -162,7 +162,9 @@ module Mongo
|
|
162
162
|
def authenticate!
|
163
163
|
if options[:user]
|
164
164
|
user = Auth::User.new(Options::Redacted.new(:auth_mech => default_mechanism).merge(options))
|
165
|
-
|
165
|
+
@server.handle_auth_failure! do
|
166
|
+
Auth.get(user).login(self)
|
167
|
+
end
|
166
168
|
end
|
167
169
|
end
|
168
170
|
|
data/lib/mongo/server/context.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.
|
@@ -19,6 +19,8 @@ module Mongo
|
|
19
19
|
# connection.
|
20
20
|
#
|
21
21
|
# @since 2.0.0
|
22
|
+
#
|
23
|
+
# @deprecated Will be removed in version 3.0
|
22
24
|
class Context
|
23
25
|
extend Forwardable
|
24
26
|
|
data/lib/mongo/server/monitor.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.
|
@@ -65,6 +65,7 @@ module Mongo
|
|
65
65
|
#
|
66
66
|
# @since 2.0.0
|
67
67
|
def get(preference = {})
|
68
|
+
return preference if PREFERENCES.values.include?(preference.class)
|
68
69
|
PREFERENCES.fetch(preference[:mode] || :primary).new(preference)
|
69
70
|
end
|
70
71
|
end
|