mongo 2.18.1 → 2.18.2
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/lib/mongo/bulk_write.rb +6 -4
- data/lib/mongo/client.rb +1 -1
- data/lib/mongo/collection/view/writable.rb +0 -2
- data/lib/mongo/collection.rb +150 -45
- data/lib/mongo/crypt/kms.rb +0 -1
- data/lib/mongo/error/invalid_read_option.rb +1 -1
- data/lib/mongo/operation/aggregate.rb +1 -2
- data/lib/mongo/operation/collections_info.rb +3 -15
- data/lib/mongo/operation/command.rb +1 -2
- data/lib/mongo/operation/count.rb +1 -2
- data/lib/mongo/operation/create.rb +1 -2
- data/lib/mongo/operation/create_index.rb +1 -2
- data/lib/mongo/operation/create_user.rb +1 -2
- data/lib/mongo/operation/delete.rb +0 -1
- data/lib/mongo/operation/distinct.rb +1 -2
- data/lib/mongo/operation/drop.rb +1 -2
- data/lib/mongo/operation/drop_database.rb +1 -2
- data/lib/mongo/operation/drop_index.rb +1 -2
- data/lib/mongo/operation/explain.rb +1 -3
- data/lib/mongo/operation/find/builder.rb +0 -1
- data/lib/mongo/operation/find.rb +1 -3
- data/lib/mongo/operation/get_more.rb +1 -3
- data/lib/mongo/operation/indexes.rb +1 -17
- data/lib/mongo/operation/insert.rb +0 -1
- data/lib/mongo/operation/kill_cursors.rb +1 -2
- data/lib/mongo/operation/list_collections.rb +1 -2
- data/lib/mongo/operation/map_reduce.rb +1 -2
- data/lib/mongo/operation/parallel_scan.rb +1 -2
- data/lib/mongo/operation/remove_user.rb +1 -2
- data/lib/mongo/operation/shared/{polymorphic_operation.rb → op_msg_executable.rb} +11 -6
- data/lib/mongo/operation/update.rb +0 -1
- data/lib/mongo/operation/update_user.rb +1 -2
- data/lib/mongo/operation/users_info.rb +1 -2
- data/lib/mongo/operation/write_command.rb +1 -2
- data/lib/mongo/operation.rb +1 -3
- data/lib/mongo/protocol.rb +0 -3
- data/lib/mongo/query_cache.rb +20 -20
- data/lib/mongo/session.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/integration/command_spec.rb +1 -23
- data/spec/mongo/client_construction_spec.rb +4 -4
- data/spec/mongo/collection_crud_spec.rb +56 -0
- data/spec/mongo/collection_spec.rb +11 -1
- data/spec/mongo/crypt/kms_spec.rb +12 -9
- data.tar.gz.sig +0 -0
- metadata +1133 -1186
- metadata.gz.sig +0 -0
- data/lib/mongo/operation/aggregate/command.rb +0 -55
- data/lib/mongo/operation/collections_info/command.rb +0 -48
- data/lib/mongo/operation/command/command.rb +0 -41
- data/lib/mongo/operation/count/command.rb +0 -47
- data/lib/mongo/operation/create/command.rb +0 -47
- data/lib/mongo/operation/create_index/command.rb +0 -61
- data/lib/mongo/operation/create_user/command.rb +0 -46
- data/lib/mongo/operation/delete/command.rb +0 -52
- data/lib/mongo/operation/distinct/command.rb +0 -47
- data/lib/mongo/operation/drop/command.rb +0 -41
- data/lib/mongo/operation/drop_database/command.rb +0 -41
- data/lib/mongo/operation/drop_index/command.rb +0 -45
- data/lib/mongo/operation/explain/command.rb +0 -58
- data/lib/mongo/operation/explain/legacy.rb +0 -52
- data/lib/mongo/operation/find/builder/legacy.rb +0 -123
- data/lib/mongo/operation/find/command.rb +0 -51
- data/lib/mongo/operation/find/legacy/result.rb +0 -46
- data/lib/mongo/operation/find/legacy.rb +0 -52
- data/lib/mongo/operation/get_more/command.rb +0 -43
- data/lib/mongo/operation/get_more/legacy.rb +0 -39
- data/lib/mongo/operation/indexes/command.rb +0 -42
- data/lib/mongo/operation/indexes/legacy.rb +0 -48
- data/lib/mongo/operation/insert/command.rb +0 -55
- data/lib/mongo/operation/kill_cursors/command.rb +0 -48
- data/lib/mongo/operation/list_collections/command.rb +0 -46
- data/lib/mongo/operation/map_reduce/command.rb +0 -51
- data/lib/mongo/operation/parallel_scan/command.rb +0 -57
- data/lib/mongo/operation/remove_user/command.rb +0 -46
- data/lib/mongo/operation/shared/op_msg_or_command.rb +0 -41
- data/lib/mongo/operation/shared/op_msg_or_find_command.rb +0 -44
- data/lib/mongo/operation/update/command.rb +0 -53
- data/lib/mongo/operation/update_user/command.rb +0 -45
- data/lib/mongo/operation/users_info/command.rb +0 -46
- data/lib/mongo/operation/write_command/command.rb +0 -51
- data/lib/mongo/protocol/delete.rb +0 -172
- data/lib/mongo/protocol/insert.rb +0 -181
- data/lib/mongo/protocol/update.rb +0 -214
- data/spec/mongo/operation/delete/command_spec.rb +0 -115
- data/spec/mongo/operation/find/legacy_spec.rb +0 -131
- data/spec/mongo/operation/get_more_spec.rb +0 -63
- data/spec/mongo/operation/insert/command_spec.rb +0 -118
- data/spec/mongo/operation/update/command_spec.rb +0 -122
- data/spec/mongo/protocol/delete_spec.rb +0 -185
- data/spec/mongo/protocol/insert_spec.rb +0 -179
- data/spec/mongo/protocol/update_spec.rb +0 -204
@@ -1,181 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
# Copyright (C) 2014-2020 MongoDB Inc.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
module Mongo
|
19
|
-
module Protocol
|
20
|
-
|
21
|
-
# MongoDB Wire protocol Insert message.
|
22
|
-
#
|
23
|
-
# This is a client request message that is sent to the server in order
|
24
|
-
# to insert documents within a namespace.
|
25
|
-
#
|
26
|
-
# The operation only has one flag +:continue_on_error+ which the user
|
27
|
-
# can use to instruct the database server to continue processing a bulk
|
28
|
-
# insertion if one happens to fail (e.g. due to duplicate IDs). This makes
|
29
|
-
# builk insert behave similarly to a seires of single inserts, except
|
30
|
-
# lastError will be set if any insert fails, not just the last one.
|
31
|
-
#
|
32
|
-
# If multiple errors occur, only the most recent will be reported by the
|
33
|
-
# getLastError mechanism.
|
34
|
-
#
|
35
|
-
# @api semipublic
|
36
|
-
class Insert < Message
|
37
|
-
|
38
|
-
# Creates a new Insert message
|
39
|
-
#
|
40
|
-
# @example Insert a user document
|
41
|
-
# Insert.new('xgen', 'users', [{:name => 'Tyler'}])
|
42
|
-
#
|
43
|
-
# @example Insert serveral user documents and continue on errors
|
44
|
-
# Insert.new('xgen', 'users', users, :flags => [:continue_on_error])
|
45
|
-
#
|
46
|
-
# @param database [String, Symbol] The database to insert into.
|
47
|
-
# @param collection [String, Symbol] The collection to insert into.
|
48
|
-
# @param documents [Array<Hash>] The documents to insert.
|
49
|
-
# @param options [Hash] Additional options for the insertion.
|
50
|
-
#
|
51
|
-
# @option options :flags [Array] The flags for the insertion message.
|
52
|
-
# Supported flags: +:continue_on_error+
|
53
|
-
# @option options [ true, false ] validating_keys Whether keys should be
|
54
|
-
# validated for being valid document keys (i.e. not begin with $ and
|
55
|
-
# not contain dots).
|
56
|
-
def initialize(database, collection, documents, options = {})
|
57
|
-
@database = database
|
58
|
-
@namespace = "#{database}.#{collection}"
|
59
|
-
@documents = documents
|
60
|
-
@flags = options[:flags] || []
|
61
|
-
@upconverter = Upconverter.new(collection, documents, options)
|
62
|
-
@options = options
|
63
|
-
super
|
64
|
-
end
|
65
|
-
|
66
|
-
# Return the event payload for monitoring.
|
67
|
-
#
|
68
|
-
# @example Return the event payload.
|
69
|
-
# message.payload
|
70
|
-
#
|
71
|
-
# @return [ BSON::Document ] The event payload.
|
72
|
-
#
|
73
|
-
# @since 2.1.0
|
74
|
-
def payload
|
75
|
-
BSON::Document.new(
|
76
|
-
command_name: 'insert',
|
77
|
-
database_name: @database,
|
78
|
-
command: upconverter.command,
|
79
|
-
request_id: request_id
|
80
|
-
)
|
81
|
-
end
|
82
|
-
|
83
|
-
protected
|
84
|
-
|
85
|
-
attr_reader :upconverter
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
def validating_keys?
|
90
|
-
@options.fetch(:validating_keys, true)
|
91
|
-
end
|
92
|
-
|
93
|
-
# The operation code required to specify an Insert message.
|
94
|
-
# @return [Fixnum] the operation code.
|
95
|
-
#
|
96
|
-
# @since 2.5.0
|
97
|
-
OP_CODE = 2002
|
98
|
-
|
99
|
-
# Available flags for an Insert message.
|
100
|
-
FLAGS = [:continue_on_error]
|
101
|
-
|
102
|
-
# @!attribute
|
103
|
-
# @return [Array<Symbol>] The flags for this Insert message.
|
104
|
-
field :flags, BitVector.new(FLAGS)
|
105
|
-
|
106
|
-
# @!attribute
|
107
|
-
# @return [String] The namespace for this Insert message.
|
108
|
-
field :namespace, CString
|
109
|
-
|
110
|
-
# @!attribute
|
111
|
-
# @return [Array<Hash>] The documents to insert.
|
112
|
-
field :documents, Document, true
|
113
|
-
|
114
|
-
# Converts legacy insert messages to the appropriare OP_COMMAND style
|
115
|
-
# message.
|
116
|
-
#
|
117
|
-
# @since 2.1.0
|
118
|
-
class Upconverter
|
119
|
-
|
120
|
-
# Insert field constant.
|
121
|
-
#
|
122
|
-
# @since 2.1.0
|
123
|
-
INSERT = 'insert'.freeze
|
124
|
-
|
125
|
-
# Documents field constant.
|
126
|
-
#
|
127
|
-
# @since 2.1.0
|
128
|
-
DOCUMENTS = 'documents'.freeze
|
129
|
-
|
130
|
-
# Write concern field constant.
|
131
|
-
#
|
132
|
-
# @since 2.1.0
|
133
|
-
WRITE_CONCERN = 'writeConcern'.freeze
|
134
|
-
|
135
|
-
# @return [ String ] collection The name of the collection.
|
136
|
-
attr_reader :collection
|
137
|
-
|
138
|
-
# @return [ Array<BSON::Document> ] documents The documents to insert.
|
139
|
-
attr_reader :documents
|
140
|
-
|
141
|
-
# @return [ Hash ] options The options.
|
142
|
-
attr_reader :options
|
143
|
-
|
144
|
-
# Instantiate the upconverter.
|
145
|
-
#
|
146
|
-
# @example Instantiate the upconverter.
|
147
|
-
# Upconverter.new('users', documents)
|
148
|
-
#
|
149
|
-
# @param [ String ] collection The name of the collection.
|
150
|
-
# @param [ Array<BSON::Document> ] documents The documents.
|
151
|
-
# @param [ Hash ] options The options.
|
152
|
-
#
|
153
|
-
# @since 2.1.0
|
154
|
-
def initialize(collection, documents, options)
|
155
|
-
@collection = collection
|
156
|
-
@documents = documents
|
157
|
-
@options = options
|
158
|
-
end
|
159
|
-
|
160
|
-
# Get the upconverted command.
|
161
|
-
#
|
162
|
-
# @example Get the command.
|
163
|
-
# upconverter.command
|
164
|
-
#
|
165
|
-
# @return [ BSON::Document ] The upconverted command.
|
166
|
-
#
|
167
|
-
# @since 2.1.0
|
168
|
-
def command
|
169
|
-
document = BSON::Document.new
|
170
|
-
document.store(INSERT, collection)
|
171
|
-
document.store(DOCUMENTS, documents)
|
172
|
-
document.store(Message::ORDERED, options.fetch(:ordered, true))
|
173
|
-
document.merge!(WRITE_CONCERN => options[:write_concern].options) if options[:write_concern]
|
174
|
-
document
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
Registry.register(OP_CODE, self)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
@@ -1,214 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
# Copyright (C) 2014-2020 MongoDB Inc.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
module Mongo
|
19
|
-
module Protocol
|
20
|
-
|
21
|
-
# MongoDB Wire protocol Update message.
|
22
|
-
#
|
23
|
-
# This is a client request message that is sent to the server in order
|
24
|
-
# to update documents matching the provided query.
|
25
|
-
#
|
26
|
-
# The default is to update a single document. In order to update many at
|
27
|
-
# a time users should set the +:multi_update+ flag for the update.
|
28
|
-
#
|
29
|
-
# If an upsert (update or insert) is desired, users can set the +:upsert+
|
30
|
-
# flag in order to indicate they would like to insert the merged selector
|
31
|
-
# and update if no document matching the update query currently exists.
|
32
|
-
#
|
33
|
-
# @api semipublic
|
34
|
-
class Update < Message
|
35
|
-
|
36
|
-
# Creates a new Update message
|
37
|
-
#
|
38
|
-
# @example Update single document
|
39
|
-
# Update.new('xgen', 'users', {:name => 'Tyler'}, {:name => 'Bob'})
|
40
|
-
#
|
41
|
-
# @example Perform a multi update
|
42
|
-
# Update.new('xgen', 'users',
|
43
|
-
# {:age => 20}, {:age => 21}, :flags => [:multi_update])
|
44
|
-
#
|
45
|
-
# @example Perform an upsert
|
46
|
-
# Update.new('xgen', 'users', {:name => 'Tyler'}, :flags => [:upsert])
|
47
|
-
#
|
48
|
-
# @param database [String, Symbol] The database to update.
|
49
|
-
# @param collection [String, Symbol] The collection to update.
|
50
|
-
# @param selector [Hash] The update selector.
|
51
|
-
# @param update [Hash] The update to perform.
|
52
|
-
# @param options [Hash] The additional query options.
|
53
|
-
#
|
54
|
-
# @option options :flags [Array] The flags for the update message.
|
55
|
-
#
|
56
|
-
# Supported flags: +:upsert+, +:multi_update+
|
57
|
-
def initialize(database, collection, selector, update, options = {})
|
58
|
-
@database = database
|
59
|
-
@collection = collection
|
60
|
-
@namespace = "#{database}.#{collection}"
|
61
|
-
@selector = selector
|
62
|
-
@update = update
|
63
|
-
@flags = options[:flags] || []
|
64
|
-
@upconverter = Upconverter.new(collection, selector, update, flags)
|
65
|
-
super
|
66
|
-
end
|
67
|
-
|
68
|
-
# Return the event payload for monitoring.
|
69
|
-
#
|
70
|
-
# @example Return the event payload.
|
71
|
-
# message.payload
|
72
|
-
#
|
73
|
-
# @return [ BSON::Document ] The event payload.
|
74
|
-
#
|
75
|
-
# @since 2.1.0
|
76
|
-
def payload
|
77
|
-
BSON::Document.new(
|
78
|
-
command_name: 'update',
|
79
|
-
database_name: @database,
|
80
|
-
command: upconverter.command,
|
81
|
-
request_id: request_id
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
protected
|
86
|
-
|
87
|
-
attr_reader :upconverter
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
# The operation code required to specify an Update message.
|
92
|
-
# @return [Fixnum] the operation code.
|
93
|
-
#
|
94
|
-
# @since 2.5.0
|
95
|
-
OP_CODE = 2001
|
96
|
-
|
97
|
-
# Available flags for an Update message.
|
98
|
-
FLAGS = [:upsert, :multi_update]
|
99
|
-
|
100
|
-
# Field representing Zero encoded as an Int32.
|
101
|
-
field :zero, Zero
|
102
|
-
|
103
|
-
# @!attribute
|
104
|
-
# @return [String] The namespace for this Update message.
|
105
|
-
field :namespace, CString
|
106
|
-
|
107
|
-
# @!attribute
|
108
|
-
# @return [Array<Symbol>] The flags for this Update message.
|
109
|
-
field :flags, BitVector.new(FLAGS)
|
110
|
-
|
111
|
-
# @!attribute
|
112
|
-
# @return [Hash] The selector for this Update message.
|
113
|
-
field :selector, Document
|
114
|
-
|
115
|
-
# @!attribute
|
116
|
-
# @return [Hash] The update for this Delete message.
|
117
|
-
field :update, Document
|
118
|
-
|
119
|
-
# Converts legacy update messages to the appropriare OP_COMMAND style
|
120
|
-
# message.
|
121
|
-
#
|
122
|
-
# @since 2.1.0
|
123
|
-
class Upconverter
|
124
|
-
|
125
|
-
# The multi constant.
|
126
|
-
#
|
127
|
-
# @since 2.2.0
|
128
|
-
MULTI = 'multi'.freeze
|
129
|
-
|
130
|
-
# The u constant.
|
131
|
-
#
|
132
|
-
# @since 2.2.0
|
133
|
-
U = 'u'.freeze
|
134
|
-
|
135
|
-
# The update constant.
|
136
|
-
#
|
137
|
-
# @since 2.2.0
|
138
|
-
UPDATE = 'update'.freeze
|
139
|
-
|
140
|
-
# The updates constant.
|
141
|
-
#
|
142
|
-
# @since 2.2.0
|
143
|
-
UPDATES = 'updates'.freeze
|
144
|
-
|
145
|
-
# The upsert constant.
|
146
|
-
#
|
147
|
-
# @since 2.2.0
|
148
|
-
UPSERT = 'upsert'.freeze
|
149
|
-
|
150
|
-
# @return [ String ] collection The name of the collection.
|
151
|
-
attr_reader :collection
|
152
|
-
|
153
|
-
# @return [ Hash ] filter The filter.
|
154
|
-
attr_reader :filter
|
155
|
-
|
156
|
-
# @return [ Hash ] update The update.
|
157
|
-
attr_reader :update
|
158
|
-
|
159
|
-
# @return [ Array<Symbol> ] flags The flags.
|
160
|
-
attr_reader :flags
|
161
|
-
|
162
|
-
# Instantiate the upconverter.
|
163
|
-
#
|
164
|
-
# @example Instantiate the upconverter.
|
165
|
-
# Upconverter.new(
|
166
|
-
# 'users',
|
167
|
-
# { name: 'test' },
|
168
|
-
# { '$set' => { 'name' => 't' }},
|
169
|
-
# []
|
170
|
-
# )
|
171
|
-
#
|
172
|
-
# @param [ String ] collection The name of the collection.
|
173
|
-
# @param [ Hash ] filter The filter.
|
174
|
-
# @param [ Hash ] update The update.
|
175
|
-
# @param [ Array<Symbol> ] flags The flags.
|
176
|
-
#
|
177
|
-
# @since 2.1.0
|
178
|
-
def initialize(collection, filter, update, flags)
|
179
|
-
@collection = collection
|
180
|
-
@filter = filter
|
181
|
-
@update = update
|
182
|
-
@flags = flags
|
183
|
-
end
|
184
|
-
|
185
|
-
# Get the upconverted command.
|
186
|
-
#
|
187
|
-
# @example Get the command.
|
188
|
-
# upconverter.command
|
189
|
-
#
|
190
|
-
# @return [ BSON::Document ] The upconverted command.
|
191
|
-
#
|
192
|
-
# @since 2.1.0
|
193
|
-
def command
|
194
|
-
document = BSON::Document.new
|
195
|
-
updates = BSON::Document.new
|
196
|
-
updates.store(Message::Q, filter)
|
197
|
-
updates.store(U, update)
|
198
|
-
if flags.include?(:multi_update)
|
199
|
-
updates.store(MULTI, true)
|
200
|
-
end
|
201
|
-
if flags.include?(:upsert)
|
202
|
-
updates.store(UPSERT, true)
|
203
|
-
end
|
204
|
-
document.store(UPDATE, collection)
|
205
|
-
document.store(Message::ORDERED, true)
|
206
|
-
document.store(UPDATES, [ updates ])
|
207
|
-
document
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
Registry.register(OP_CODE, self)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
describe Mongo::Operation::Delete::Command do
|
7
|
-
|
8
|
-
let(:write_concern) do
|
9
|
-
Mongo::WriteConcern.get(w: :majority)
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:session) { nil }
|
13
|
-
let(:deletes) { [{:q => { :foo => 1 }, :limit => 1}] }
|
14
|
-
let(:spec) do
|
15
|
-
{ :deletes => deletes,
|
16
|
-
:db_name => authorized_collection.database.name,
|
17
|
-
:coll_name => authorized_collection.name,
|
18
|
-
:write_concern => write_concern,
|
19
|
-
:ordered => true,
|
20
|
-
:session => session
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:op) { described_class.new(spec) }
|
25
|
-
|
26
|
-
describe '#initialize' do
|
27
|
-
|
28
|
-
context 'spec' do
|
29
|
-
|
30
|
-
it 'sets the spec' do
|
31
|
-
expect(op.spec).to eq(spec)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#==' do
|
37
|
-
|
38
|
-
context 'spec' do
|
39
|
-
|
40
|
-
context 'when two ops have the same specs' do
|
41
|
-
let(:other) { described_class.new(spec) }
|
42
|
-
|
43
|
-
it 'returns true' do
|
44
|
-
expect(op).to eq(other)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when two ops have different specs' do
|
49
|
-
let(:other_deletes) { [{:q => { :bar => 1 }, :limit => 1}] }
|
50
|
-
let(:other_spec) do
|
51
|
-
{ :deletes => other_deletes,
|
52
|
-
:db_name => authorized_collection.database.name,
|
53
|
-
:coll_name => authorized_collection.name,
|
54
|
-
:write_concern => write_concern,
|
55
|
-
:ordered => true
|
56
|
-
}
|
57
|
-
end
|
58
|
-
let(:other) { described_class.new(other_spec) }
|
59
|
-
|
60
|
-
it 'returns false' do
|
61
|
-
expect(op).not_to eq(other)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'write concern' do
|
68
|
-
|
69
|
-
context 'when write concern is not specified' do
|
70
|
-
|
71
|
-
let(:spec) do
|
72
|
-
{ :deletes => deletes,
|
73
|
-
:db_name => authorized_collection.database.name,
|
74
|
-
:coll_name => authorized_collection.name,
|
75
|
-
:ordered => true
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'does not include write concern in the selector' do
|
80
|
-
expect(op.send(:command, double('server'))[:writeConcern]).to be_nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'when write concern is specified' do
|
85
|
-
|
86
|
-
it 'includes write concern in the selector' do
|
87
|
-
expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#message' do
|
93
|
-
|
94
|
-
context 'when the server does not support OP_MSG' do
|
95
|
-
max_server_version '3.4'
|
96
|
-
|
97
|
-
let(:expected_selector) do
|
98
|
-
{
|
99
|
-
:delete => authorized_collection.name,
|
100
|
-
:deletes => deletes,
|
101
|
-
:writeConcern => write_concern.options,
|
102
|
-
:ordered => true
|
103
|
-
}
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'creates the correct query wire protocol message' do
|
107
|
-
expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
|
108
|
-
'$cmd',
|
109
|
-
expected_selector,
|
110
|
-
{ limit: -1 } )
|
111
|
-
op.send(:message, authorized_primary)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
describe Mongo::Operation::Find::Legacy do
|
7
|
-
max_server_version '3.4'
|
8
|
-
|
9
|
-
let(:context) { Mongo::Operation::Context.new }
|
10
|
-
|
11
|
-
let(:selector) { { foo: 1 } }
|
12
|
-
let(:query_options) { {} }
|
13
|
-
let(:spec) do
|
14
|
-
{ :selector => selector,
|
15
|
-
:options => query_options,
|
16
|
-
:db_name => authorized_collection.database.name,
|
17
|
-
:coll_name => authorized_collection.name,
|
18
|
-
:read => Mongo::ServerSelector.get
|
19
|
-
}
|
20
|
-
end
|
21
|
-
let(:op) { described_class.new(spec) }
|
22
|
-
|
23
|
-
describe '#initialize' do
|
24
|
-
|
25
|
-
context 'query spec' do
|
26
|
-
it 'sets the query spec' do
|
27
|
-
expect(op.spec).to be(spec)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#==' do
|
33
|
-
|
34
|
-
context 'when two ops have different specs' do
|
35
|
-
let(:other_spec) do
|
36
|
-
{ :selector => { :a => 1 },
|
37
|
-
:options => query_options,
|
38
|
-
:db_name => authorized_collection.database.name,
|
39
|
-
:coll_name => authorized_collection.name
|
40
|
-
}
|
41
|
-
end
|
42
|
-
let(:other) { described_class.new(other_spec) }
|
43
|
-
|
44
|
-
it 'returns false' do
|
45
|
-
expect(op).not_to eq(other)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#message' do
|
51
|
-
|
52
|
-
let(:query_options) do
|
53
|
-
{ :flags => [ :no_cursor_timeout ]}
|
54
|
-
end
|
55
|
-
|
56
|
-
let(:query) do
|
57
|
-
described_class.new(spec)
|
58
|
-
end
|
59
|
-
|
60
|
-
let(:cluster_single) do
|
61
|
-
double('cluster').tap do |c|
|
62
|
-
allow(c).to receive(:single?).and_return(true)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
let(:message) do
|
67
|
-
authorized_primary.with_connection do |connection|
|
68
|
-
query.send(:message, connection)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'applies the correct flags' do
|
73
|
-
expect(message.flags).to eq(query_options[:flags])
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when the server is a secondary' do
|
77
|
-
let(:description) do
|
78
|
-
double('description').tap do |description|
|
79
|
-
expect(description).to receive(:mongos?) { false }
|
80
|
-
expect(description).to receive(:standalone?) { false }
|
81
|
-
#expect(description).to receive(:load_balancer?) { false }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
let(:connection) do
|
86
|
-
double('connection').tap do |conn|
|
87
|
-
expect(conn).to receive(:description).at_least(:once).and_return(description)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
let(:secondary_server_single) do
|
92
|
-
double('secondary_server').tap do |server|
|
93
|
-
expect(server).to receive(:with_connection).and_yield(connection)
|
94
|
-
expect(server).to receive(:cluster) { cluster_single }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
let(:message) do
|
99
|
-
secondary_server_single.with_connection do |connection|
|
100
|
-
query.send(:message, connection)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
before do
|
105
|
-
allow(connection).to receive(:server) { secondary_server_single }
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'applies the correct flags' do
|
109
|
-
expect(message.flags).to eq([ :no_cursor_timeout, :secondary_ok ])
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "when the document contains an 'ok' field" do
|
114
|
-
|
115
|
-
before do
|
116
|
-
authorized_collection.insert_one(ok: false)
|
117
|
-
end
|
118
|
-
|
119
|
-
after do
|
120
|
-
authorized_collection.delete_many
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'does not raise an exception' do
|
124
|
-
authorized_primary.with_connection do |connection|
|
125
|
-
expect(op.execute(connection, context: context)).to be_a(Mongo::Operation::Find::Legacy::Result)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
describe Mongo::Operation::GetMore::Legacy do
|
7
|
-
|
8
|
-
let(:to_return) do
|
9
|
-
50
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:cursor_id) do
|
13
|
-
1
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:spec) do
|
17
|
-
{ :db_name => SpecConfig.instance.test_db,
|
18
|
-
:coll_name => TEST_COLL,
|
19
|
-
:to_return => to_return,
|
20
|
-
:cursor_id => cursor_id }
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:op) { described_class.new(spec) }
|
24
|
-
|
25
|
-
let(:context) { Mongo::Operation::Context.new }
|
26
|
-
|
27
|
-
describe '#initialize' do
|
28
|
-
|
29
|
-
it 'sets the spec' do
|
30
|
-
expect(op.spec).to be(spec)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#==' do
|
35
|
-
|
36
|
-
context ' when two ops have different specs' do
|
37
|
-
let(:other_spec) do
|
38
|
-
{ :db_name => 'test_db',
|
39
|
-
:coll_name => 'test_coll',
|
40
|
-
:to_return => 50,
|
41
|
-
:cursor_id => 2 }
|
42
|
-
end
|
43
|
-
let(:other) { described_class.new(other_spec) }
|
44
|
-
|
45
|
-
it 'returns false' do
|
46
|
-
expect(op).not_to eq(other)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#message' do
|
52
|
-
|
53
|
-
it 'creates a get more wire protocol message with correct specs' do
|
54
|
-
expect(Mongo::Protocol::GetMore).to receive(:new).with(SpecConfig.instance.test_db, TEST_COLL, to_return, cursor_id).and_call_original
|
55
|
-
begin
|
56
|
-
authorized_primary.with_connection do |connection|
|
57
|
-
op.execute(connection, context: context)
|
58
|
-
end
|
59
|
-
rescue
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|