mongo 2.1.2 → 2.2.0.rc0
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/README.md +10 -3
- data/Rakefile +1 -7
- data/lib/csasl/csasl.bundle +0 -0
- data/lib/mongo/auth/user/view.rb +1 -1
- data/lib/mongo/bulk_write.rb +7 -1
- data/lib/mongo/client.rb +17 -15
- data/lib/mongo/cluster.rb +4 -2
- data/lib/mongo/collection.rb +36 -2
- data/lib/mongo/collection/view.rb +24 -21
- data/lib/mongo/collection/view/aggregation.rb +5 -42
- data/lib/mongo/collection/view/builder.rb +20 -0
- data/lib/mongo/collection/view/builder/aggregation.rb +98 -0
- data/lib/mongo/collection/view/builder/find_command.rb +111 -0
- data/lib/mongo/collection/view/builder/flags.rb +62 -0
- data/lib/mongo/collection/view/builder/map_reduce.rb +134 -0
- data/lib/mongo/collection/view/builder/modifiers.rb +80 -0
- data/lib/mongo/collection/view/builder/op_query.rb +83 -0
- data/lib/mongo/collection/view/explainable.rb +15 -0
- data/lib/mongo/collection/view/immutable.rb +5 -12
- data/lib/mongo/collection/view/iterable.rb +24 -2
- data/lib/mongo/collection/view/map_reduce.rb +18 -27
- data/lib/mongo/collection/view/readable.rb +70 -112
- data/lib/mongo/collection/view/writable.rb +23 -7
- data/lib/mongo/cursor.rb +76 -25
- data/lib/mongo/cursor/builder.rb +18 -0
- data/lib/mongo/cursor/builder/get_more_command.rb +71 -0
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +62 -0
- data/lib/mongo/cursor/builder/op_get_more.rb +61 -0
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +56 -0
- data/lib/mongo/database.rb +2 -2
- data/lib/mongo/database/view.rb +9 -5
- data/lib/mongo/dbref.rb +3 -3
- data/lib/mongo/error.rb +1 -0
- data/lib/mongo/error/invalid_write_concern.rb +35 -0
- data/lib/mongo/grid/file/chunk.rb +2 -2
- data/lib/mongo/index/view.rb +5 -2
- data/lib/mongo/operation.rb +1 -0
- data/lib/mongo/operation/commands.rb +2 -0
- data/lib/mongo/operation/commands/aggregate.rb +39 -45
- data/lib/mongo/operation/commands/aggregate/result.rb +54 -68
- data/lib/mongo/operation/commands/collections_info.rb +38 -36
- data/lib/mongo/operation/commands/collections_info/result.rb +17 -15
- data/lib/mongo/operation/commands/command.rb +24 -22
- data/lib/mongo/operation/commands/find.rb +27 -0
- data/lib/mongo/operation/commands/find/result.rb +62 -0
- data/lib/mongo/operation/commands/get_more.rb +27 -0
- data/lib/mongo/operation/commands/get_more/result.rb +62 -0
- data/lib/mongo/operation/commands/indexes.rb +41 -39
- data/lib/mongo/operation/commands/list_collections.rb +25 -31
- data/lib/mongo/operation/commands/list_collections/result.rb +63 -81
- data/lib/mongo/operation/commands/list_indexes.rb +27 -35
- data/lib/mongo/operation/commands/list_indexes/result.rb +67 -85
- data/lib/mongo/operation/commands/map_reduce.rb +29 -37
- data/lib/mongo/operation/commands/map_reduce/result.rb +85 -88
- data/lib/mongo/operation/commands/parallel_scan.rb +29 -33
- data/lib/mongo/operation/commands/parallel_scan/result.rb +34 -42
- data/lib/mongo/operation/commands/user_query.rb +40 -38
- data/lib/mongo/operation/commands/users_info.rb +24 -29
- data/lib/mongo/operation/commands/users_info/result.rb +13 -11
- data/lib/mongo/operation/object_id_generator.rb +36 -0
- data/lib/mongo/operation/result.rb +30 -0
- data/lib/mongo/operation/specifiable.rb +35 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +4 -3
- data/lib/mongo/operation/write/bulk/delete/result.rb +18 -25
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +2 -2
- data/lib/mongo/operation/write/command/delete.rb +3 -2
- data/lib/mongo/operation/write/command/insert.rb +4 -2
- data/lib/mongo/operation/write/command/update.rb +6 -3
- data/lib/mongo/operation/write/gle.rb +2 -1
- data/lib/mongo/operation/write/idable.rb +19 -2
- data/lib/mongo/options/mapper.rb +22 -0
- data/lib/mongo/protocol/bit_vector.rb +3 -3
- data/lib/mongo/protocol/delete.rb +15 -5
- data/lib/mongo/protocol/get_more.rb +10 -5
- data/lib/mongo/protocol/insert.rb +1 -6
- data/lib/mongo/protocol/kill_cursors.rb +14 -1
- data/lib/mongo/protocol/message.rb +32 -8
- data/lib/mongo/protocol/serializers.rb +15 -16
- data/lib/mongo/protocol/update.rb +35 -12
- data/lib/mongo/server/connectable.rb +3 -1
- data/lib/mongo/server/connection.rb +5 -5
- data/lib/mongo/server/description.rb +8 -2
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/monitor.rb +1 -12
- data/lib/mongo/server/monitor/connection.rb +30 -26
- data/lib/mongo/server_selector/selectable.rb +21 -4
- data/lib/mongo/uri.rb +2 -0
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +21 -6
- data/mongo.gemspec +1 -2
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +13 -0
- data/spec/mongo/bulk_write_spec.rb +58 -0
- data/spec/mongo/client_spec.rb +6 -4
- data/spec/mongo/collection/view/builder/find_command_spec.rb +167 -0
- data/spec/mongo/collection/view/builder/flags_spec.rb +106 -0
- data/spec/mongo/collection/view/builder/modifiers_spec.rb +210 -0
- data/spec/mongo/collection/view/builder/op_query_spec.rb +154 -0
- data/spec/mongo/collection/view/explainable_spec.rb +1 -2
- data/spec/mongo/collection/view/immutable_spec.rb +3 -52
- data/spec/mongo/collection/view/map_reduce_spec.rb +12 -12
- data/spec/mongo/collection/view/readable_spec.rb +86 -80
- data/spec/mongo/collection/view_spec.rb +109 -703
- data/spec/mongo/collection_spec.rb +594 -11
- data/spec/mongo/command_monitoring_spec.rb +40 -27
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +160 -0
- data/spec/mongo/cursor/builder/op_get_more_spec.rb +52 -0
- data/spec/mongo/cursor_spec.rb +10 -60
- data/spec/mongo/database_spec.rb +24 -3
- data/spec/mongo/dbref_spec.rb +4 -4
- data/spec/mongo/grid/file/chunk_spec.rb +1 -1
- data/spec/mongo/grid/fs_bucket_spec.rb +3 -3
- data/spec/mongo/index/view_spec.rb +41 -0
- data/spec/mongo/operation/{aggregate → commands/aggregate}/result_spec.rb +1 -1
- data/spec/mongo/operation/commands/aggregate_spec.rb +1 -1
- data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/commands/command_spec.rb +1 -1
- data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
- data/spec/mongo/operation/commands/map_reduce_spec.rb +1 -1
- data/spec/mongo/operation/write/command/delete_spec.rb +25 -0
- data/spec/mongo/operation/write/command/insert_spec.rb +25 -0
- data/spec/mongo/operation/write/command/update_spec.rb +25 -0
- data/spec/mongo/protocol/delete_spec.rb +4 -4
- data/spec/mongo/protocol/get_more_spec.rb +4 -4
- data/spec/mongo/protocol/insert_spec.rb +3 -3
- data/spec/mongo/protocol/kill_cursors_spec.rb +3 -3
- data/spec/mongo/protocol/query_spec.rb +7 -7
- data/spec/mongo/protocol/update_spec.rb +5 -5
- data/spec/mongo/server/description/features_spec.rb +25 -0
- data/spec/mongo/write_concern_spec.rb +126 -0
- data/spec/spec_helper.rb +9 -19
- data/spec/support/command_monitoring.rb +8 -0
- data/spec/support/command_monitoring/find.yml +53 -4
- data/spec/support/matchers.rb +1 -1
- data/spec/support/shared/protocol.rb +5 -5
- data/spec/support/travis.rb +1 -1
- metadata +43 -10
- metadata.gz.sig +0 -0
data/lib/mongo/options/mapper.rb
CHANGED
@@ -42,6 +42,28 @@ module Mongo
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
# Transforms the provided options to a new set of options given the
|
46
|
+
# provided mapping. Expects BSON::Documents in and out so no explicit
|
47
|
+
# string conversion needs to happen.
|
48
|
+
#
|
49
|
+
# @example Transform the options.
|
50
|
+
# Mapper.transform_documents({ name: 1 }, { :name => :nombre })
|
51
|
+
#
|
52
|
+
# @param [ BSON::Document ] options The options to transform
|
53
|
+
# @param [ BSON::Document ] mappings The key mappings.
|
54
|
+
# @param [ BSON::Document ] document The output document.
|
55
|
+
#
|
56
|
+
# @return [ BSON::Document ] The transformed options.
|
57
|
+
#
|
58
|
+
# @since 2.0.0
|
59
|
+
def transform_documents(options, mappings, document = BSON::Document.new)
|
60
|
+
options.reduce(document) do |transformed, (key, value)|
|
61
|
+
name = mappings[key]
|
62
|
+
transformed[name] = value if name && !value.nil?
|
63
|
+
transformed
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
45
67
|
# Coverts all the keys of the options to strings.
|
46
68
|
#
|
47
69
|
# @example Convert all option keys to strings.
|
@@ -40,15 +40,15 @@ module Mongo
|
|
40
40
|
def serialize(buffer, value)
|
41
41
|
bits = 0
|
42
42
|
value.each { |flag| bits |= @masks[flag] }
|
43
|
-
buffer
|
43
|
+
buffer.put_int32(bits)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Deserializes vector by decoding the symbol according to its mask
|
47
47
|
#
|
48
48
|
# @param io [IO] Stream containing the vector to be deserialized
|
49
49
|
# @return [Array<Symbol>] Flags contained in the vector
|
50
|
-
def deserialize(
|
51
|
-
vector =
|
50
|
+
def deserialize(buffer)
|
51
|
+
vector = buffer.get_int32
|
52
52
|
flags = []
|
53
53
|
@masks.each do |flag, mask|
|
54
54
|
flags << flag if mask & vector != 0
|
@@ -99,6 +99,16 @@ module Mongo
|
|
99
99
|
# @since 2.1.0
|
100
100
|
class Upconverter
|
101
101
|
|
102
|
+
# The delete command constant.
|
103
|
+
#
|
104
|
+
# @since 2.2.0
|
105
|
+
DELETE = 'delete'.freeze
|
106
|
+
|
107
|
+
# The deletes command constant.
|
108
|
+
#
|
109
|
+
# @since 2.2.0
|
110
|
+
DELETES = 'deletes'.freeze
|
111
|
+
|
102
112
|
# @return [ String ] collection The name of the collection.
|
103
113
|
attr_reader :collection
|
104
114
|
|
@@ -132,11 +142,11 @@ module Mongo
|
|
132
142
|
#
|
133
143
|
# @since 2.1.0
|
134
144
|
def command
|
135
|
-
BSON::Document.new
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
145
|
+
document = BSON::Document.new
|
146
|
+
document.store(DELETE, collection)
|
147
|
+
document.store(DELETES, [ BSON::Document.new(Message::Q => filter, Message::LIMIT => limit) ])
|
148
|
+
document.store(Message::ORDERED, true)
|
149
|
+
document
|
140
150
|
end
|
141
151
|
|
142
152
|
private
|
@@ -104,6 +104,11 @@ module Mongo
|
|
104
104
|
# @since 2.1.0
|
105
105
|
class Upconverter
|
106
106
|
|
107
|
+
# The get more constant.
|
108
|
+
#
|
109
|
+
# @since 2.2.0
|
110
|
+
GET_MORE = 'getMore'.freeze
|
111
|
+
|
107
112
|
# @return [ String ] collection The name of the collection.
|
108
113
|
attr_reader :collection
|
109
114
|
|
@@ -139,11 +144,11 @@ module Mongo
|
|
139
144
|
#
|
140
145
|
# @since 2.1.0
|
141
146
|
def command
|
142
|
-
BSON::Document.new
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
+
document = BSON::Document.new
|
148
|
+
document.store(GET_MORE, cursor_id)
|
149
|
+
document.store(Message::BATCH_SIZE, number_to_return)
|
150
|
+
document.store(Message::COLLECTION, collection)
|
151
|
+
document
|
147
152
|
end
|
148
153
|
end
|
149
154
|
end
|
@@ -114,11 +114,6 @@ module Mongo
|
|
114
114
|
# @since 2.1.0
|
115
115
|
DOCUMENTS = 'documents'.freeze
|
116
116
|
|
117
|
-
# Ordered field constant.
|
118
|
-
#
|
119
|
-
# @since 2.1.0
|
120
|
-
ORDERED = 'ordered'.freeze
|
121
|
-
|
122
117
|
# Write concern field constant.
|
123
118
|
#
|
124
119
|
# @since 2.1.0
|
@@ -161,7 +156,7 @@ module Mongo
|
|
161
156
|
document = BSON::Document.new
|
162
157
|
document.store(INSERT, collection)
|
163
158
|
document.store(DOCUMENTS, documents)
|
164
|
-
document.store(ORDERED, options.fetch(:ordered, true))
|
159
|
+
document.store(Message::ORDERED, options.fetch(:ordered, true))
|
165
160
|
document.merge!(WRITE_CONCERN => options[:write_concern].options) if options[:write_concern]
|
166
161
|
document
|
167
162
|
end
|
@@ -82,6 +82,16 @@ module Mongo
|
|
82
82
|
# @since 2.1.0
|
83
83
|
class Upconverter
|
84
84
|
|
85
|
+
# The kill cursors constant.
|
86
|
+
#
|
87
|
+
# @since 2.2.0
|
88
|
+
KILL_CURSORS = 'killCursors'.freeze
|
89
|
+
|
90
|
+
# The cursors constant.
|
91
|
+
#
|
92
|
+
# @since 2.2.0
|
93
|
+
CURSORS = 'cursors'.freeze
|
94
|
+
|
85
95
|
# @return [ String ] collection The name of the collection.
|
86
96
|
attr_reader :collection
|
87
97
|
|
@@ -111,7 +121,10 @@ module Mongo
|
|
111
121
|
#
|
112
122
|
# @since 2.1.0
|
113
123
|
def command
|
114
|
-
BSON::Document.new
|
124
|
+
document = BSON::Document.new
|
125
|
+
document.store(KILL_CURSORS, collection)
|
126
|
+
document.store(CURSORS, cursor_ids)
|
127
|
+
document
|
115
128
|
end
|
116
129
|
end
|
117
130
|
end
|
@@ -42,6 +42,31 @@ module Mongo
|
|
42
42
|
class Message
|
43
43
|
include Serializers
|
44
44
|
|
45
|
+
# The batch size constant.
|
46
|
+
#
|
47
|
+
# @since 2.2.0
|
48
|
+
BATCH_SIZE = 'batchSize'.freeze
|
49
|
+
|
50
|
+
# The collection constant.
|
51
|
+
#
|
52
|
+
# @since 2.2.0
|
53
|
+
COLLECTION = 'collection'.freeze
|
54
|
+
|
55
|
+
# The limit constant.
|
56
|
+
#
|
57
|
+
# @since 2.2.0
|
58
|
+
LIMIT = 'limit'.freeze
|
59
|
+
|
60
|
+
# The ordered constant.
|
61
|
+
#
|
62
|
+
# @since 2.2.0
|
63
|
+
ORDERED = 'ordered'.freeze
|
64
|
+
|
65
|
+
# The q constant.
|
66
|
+
#
|
67
|
+
# @since 2.2.0
|
68
|
+
Q = 'q'.freeze
|
69
|
+
|
45
70
|
# Returns the request id for the message
|
46
71
|
#
|
47
72
|
# @return [Fixnum] The request id for this message
|
@@ -64,13 +89,11 @@ module Mongo
|
|
64
89
|
#
|
65
90
|
# @param buffer [String] buffer where the message should be inserted
|
66
91
|
# @return [String] buffer containing the serialized message
|
67
|
-
def serialize(buffer =
|
68
|
-
start = buffer.
|
92
|
+
def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil)
|
93
|
+
start = buffer.length
|
69
94
|
serialize_header(buffer)
|
70
95
|
serialize_fields(buffer, max_bson_size)
|
71
|
-
|
72
|
-
buffer[start, 4] = Int32.serialize('', length)
|
73
|
-
buffer
|
96
|
+
buffer.replace_int32(start, buffer.length - start)
|
74
97
|
end
|
75
98
|
|
76
99
|
alias_method :to_s, :serialize
|
@@ -80,13 +103,14 @@ module Mongo
|
|
80
103
|
# @param io [IO] Stream containing a message
|
81
104
|
# @return [Message] Instance of a Message class
|
82
105
|
def self.deserialize(io)
|
83
|
-
deserialize_header(io)
|
106
|
+
length = deserialize_header(BSON::ByteBuffer.new(io.read(16))).first
|
107
|
+
buffer = BSON::ByteBuffer.new(io.read(length - 16))
|
84
108
|
message = allocate
|
85
109
|
fields.each do |field|
|
86
110
|
if field[:multi]
|
87
|
-
deserialize_array(message,
|
111
|
+
deserialize_array(message, buffer, field)
|
88
112
|
else
|
89
|
-
deserialize_field(message,
|
113
|
+
deserialize_field(message, buffer, field)
|
90
114
|
end
|
91
115
|
end
|
92
116
|
message
|
@@ -50,7 +50,7 @@ module Mongo
|
|
50
50
|
# @param value [String] Header value to be serialized.
|
51
51
|
# @return [String] Buffer with serialized value.
|
52
52
|
def self.serialize(buffer, value)
|
53
|
-
buffer
|
53
|
+
buffer.put_bytes(value.pack(HEADER_PACK))
|
54
54
|
end
|
55
55
|
|
56
56
|
# Deserializes the header value from the IO stream
|
@@ -58,8 +58,8 @@ module Mongo
|
|
58
58
|
# @param io [IO] IO stream containing the message header.
|
59
59
|
# @return [Array<Fixnum>] Array consisting of the deserialized
|
60
60
|
# length, request id, response id, and op code.
|
61
|
-
def self.deserialize(
|
62
|
-
|
61
|
+
def self.deserialize(buffer)
|
62
|
+
buffer.get_bytes(16).unpack(HEADER_PACK)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -74,8 +74,7 @@ module Mongo
|
|
74
74
|
# @param value [String] The string to be serialized.
|
75
75
|
# @return [String] Buffer with serialized value.
|
76
76
|
def self.serialize(buffer, value)
|
77
|
-
buffer
|
78
|
-
buffer << NULL
|
77
|
+
buffer.put_cstring(value)
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
@@ -90,7 +89,7 @@ module Mongo
|
|
90
89
|
# @param value [Fixnum] Ignored value.
|
91
90
|
# @return [String] Buffer with serialized value.
|
92
91
|
def self.serialize(buffer, value)
|
93
|
-
buffer
|
92
|
+
buffer.put_int32(ZERO)
|
94
93
|
end
|
95
94
|
end
|
96
95
|
|
@@ -105,15 +104,15 @@ module Mongo
|
|
105
104
|
# @param value [Fixnum] 32-bit integer to be serialized.
|
106
105
|
# @return [String] Buffer with serialized value.
|
107
106
|
def self.serialize(buffer, value)
|
108
|
-
buffer
|
107
|
+
buffer.put_int32(value)
|
109
108
|
end
|
110
109
|
|
111
110
|
# Deserializes a 32-bit Fixnum from the IO stream
|
112
111
|
#
|
113
112
|
# @param io [IO] IO stream containing the 32-bit integer
|
114
113
|
# @return [Fixnum] Deserialized Int32
|
115
|
-
def self.deserialize(
|
116
|
-
|
114
|
+
def self.deserialize(buffer)
|
115
|
+
buffer.get_int32
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
@@ -128,15 +127,15 @@ module Mongo
|
|
128
127
|
# @param value [Fixnum] 64-bit integer to be serialized.
|
129
128
|
# @return [String] Buffer with serialized value.
|
130
129
|
def self.serialize(buffer, value)
|
131
|
-
buffer
|
130
|
+
buffer.put_int64(value)
|
132
131
|
end
|
133
132
|
|
134
133
|
# Deserializes a 64-bit Fixnum from the IO stream
|
135
134
|
#
|
136
135
|
# @param io [IO] IO stream containing the 64-bit integer.
|
137
136
|
# @return [Fixnum] Deserialized Int64.
|
138
|
-
def self.deserialize(
|
139
|
-
|
137
|
+
def self.deserialize(buffer)
|
138
|
+
buffer.get_int64
|
140
139
|
end
|
141
140
|
end
|
142
141
|
|
@@ -151,9 +150,9 @@ module Mongo
|
|
151
150
|
# @param value [Hash] Document to serialize as BSON.
|
152
151
|
# @return [String] Buffer with serialized value.
|
153
152
|
def self.serialize(buffer, value, max_bson_size = nil)
|
154
|
-
start_size = buffer.
|
153
|
+
start_size = buffer.length
|
155
154
|
value.to_bson(buffer)
|
156
|
-
if max_bson_size && buffer.
|
155
|
+
if max_bson_size && buffer.length - start_size > max_bson_size
|
157
156
|
raise Error::MaxBSONSize.new(max_bson_size)
|
158
157
|
end
|
159
158
|
end
|
@@ -162,8 +161,8 @@ module Mongo
|
|
162
161
|
#
|
163
162
|
# @param io [IO] IO stream containing the BSON encoded document.
|
164
163
|
# @return [Hash] The decoded BSON document.
|
165
|
-
def self.deserialize(
|
166
|
-
BSON::Document.from_bson(
|
164
|
+
def self.deserialize(buffer)
|
165
|
+
BSON::Document.from_bson(buffer)
|
167
166
|
end
|
168
167
|
|
169
168
|
# Whether there can be a size limit on this type after serialization.
|
@@ -116,6 +116,31 @@ module Mongo
|
|
116
116
|
# @since 2.1.0
|
117
117
|
class Upconverter
|
118
118
|
|
119
|
+
# The multi constant.
|
120
|
+
#
|
121
|
+
# @since 2.2.0
|
122
|
+
MULTI = 'multi'.freeze
|
123
|
+
|
124
|
+
# The u constant.
|
125
|
+
#
|
126
|
+
# @since 2.2.0
|
127
|
+
U = 'u'.freeze
|
128
|
+
|
129
|
+
# The update constant.
|
130
|
+
#
|
131
|
+
# @since 2.2.0
|
132
|
+
UPDATE = 'update'.freeze
|
133
|
+
|
134
|
+
# The updates constant.
|
135
|
+
#
|
136
|
+
# @since 2.2.0
|
137
|
+
UPDATES = 'updates'.freeze
|
138
|
+
|
139
|
+
# The upsert constant.
|
140
|
+
#
|
141
|
+
# @since 2.2.0
|
142
|
+
UPSERT = 'upsert'.freeze
|
143
|
+
|
119
144
|
# @return [ String ] collection The name of the collection.
|
120
145
|
attr_reader :collection
|
121
146
|
|
@@ -160,18 +185,16 @@ module Mongo
|
|
160
185
|
#
|
161
186
|
# @since 2.1.0
|
162
187
|
def command
|
163
|
-
BSON::Document.new
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
]
|
174
|
-
)
|
188
|
+
document = BSON::Document.new
|
189
|
+
updates = BSON::Document.new
|
190
|
+
updates.store(Message::Q, filter)
|
191
|
+
updates.store(U, update)
|
192
|
+
updates.store(MULTI, flags.include?(:multi_update))
|
193
|
+
updates.store(UPSERT, flags.include?(:upsert))
|
194
|
+
document.store(UPDATE, collection)
|
195
|
+
document.store(Message::ORDERED, true)
|
196
|
+
document.store(UPDATES, [ updates ])
|
197
|
+
document
|
175
198
|
end
|
176
199
|
end
|
177
200
|
end
|
@@ -36,7 +36,7 @@ module Mongo
|
|
36
36
|
# The ping message as raw bytes.
|
37
37
|
#
|
38
38
|
# @since 2.1.0
|
39
|
-
PING_BYTES = PING_MESSAGE.serialize.freeze
|
39
|
+
PING_BYTES = PING_MESSAGE.serialize.to_s.freeze
|
40
40
|
|
41
41
|
# @return [ Mongo::Auth::CR, Mongo::Auth::X509, Mongo::Auth:LDAP, Mongo::Auth::SCRAM ]
|
42
42
|
# authenticator The authentication strategy.
|
@@ -188,17 +188,17 @@ module Mongo
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
def write(messages, buffer =
|
191
|
+
def write(messages, buffer = BSON::ByteBuffer.new)
|
192
192
|
start_size = 0
|
193
193
|
messages.each do |message|
|
194
194
|
message.serialize(buffer, max_bson_object_size)
|
195
195
|
if max_message_size &&
|
196
|
-
(buffer.
|
196
|
+
(buffer.length - start_size) > max_message_size
|
197
197
|
raise Error::MaxMessageSize.new(max_message_size)
|
198
|
-
start_size = buffer.
|
198
|
+
start_size = buffer.length
|
199
199
|
end
|
200
200
|
end
|
201
|
-
ensure_connected{ |socket| socket.write(buffer) }
|
201
|
+
ensure_connected{ |socket| socket.write(buffer.to_s) }
|
202
202
|
end
|
203
203
|
end
|
204
204
|
end
|
@@ -142,7 +142,7 @@ module Mongo
|
|
142
142
|
# Fields to exclude when comparing two descriptions.
|
143
143
|
#
|
144
144
|
# @since 2.0.6
|
145
|
-
EXCLUDE_FOR_COMPARISON = [ LOCAL_TIME, ELECTION_ID ]
|
145
|
+
EXCLUDE_FOR_COMPARISON = [ LOCAL_TIME, ELECTION_ID ].freeze
|
146
146
|
|
147
147
|
# @return [ Address ] address The server's address.
|
148
148
|
attr_reader :address
|
@@ -553,11 +553,17 @@ module Mongo
|
|
553
553
|
def ==(other)
|
554
554
|
return false if self.class != other.class
|
555
555
|
return true if config == other.config
|
556
|
+
compare_config(other)
|
557
|
+
end
|
558
|
+
alias_method :eql?, :==
|
559
|
+
|
560
|
+
private
|
561
|
+
|
562
|
+
def compare_config(other)
|
556
563
|
!config.keys.empty? && config.keys.all? do |k|
|
557
564
|
config[k] == other.config[k] || EXCLUDE_FOR_COMPARISON.include?(k)
|
558
565
|
end
|
559
566
|
end
|
560
|
-
alias_method :eql?, :==
|
561
567
|
end
|
562
568
|
end
|
563
569
|
end
|