mongo 2.3.1 → 2.4.0.rc0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -3
- data/lib/mongo/bulk_write.rb +8 -7
- data/lib/mongo/bulk_write/combineable.rb +4 -0
- data/lib/mongo/bulk_write/transformable.rb +17 -5
- data/lib/mongo/bulk_write/validatable.rb +1 -0
- data/lib/mongo/client.rb +3 -0
- data/lib/mongo/cluster.rb +8 -0
- data/lib/mongo/cluster/app_metadata.rb +135 -0
- data/lib/mongo/collection.rb +42 -10
- data/lib/mongo/collection/view.rb +15 -1
- data/lib/mongo/collection/view/aggregation.rb +5 -0
- data/lib/mongo/collection/view/builder/aggregation.rb +13 -3
- data/lib/mongo/collection/view/builder/find_command.rb +7 -21
- data/lib/mongo/collection/view/builder/map_reduce.rb +22 -5
- data/lib/mongo/collection/view/iterable.rb +1 -0
- data/lib/mongo/collection/view/map_reduce.rb +5 -0
- data/lib/mongo/collection/view/readable.rb +35 -14
- data/lib/mongo/collection/view/writable.rb +54 -23
- data/lib/mongo/cursor/builder/get_more_command.rb +2 -3
- data/lib/mongo/database.rb +10 -2
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/error/invalid_application_name.rb +38 -0
- data/lib/mongo/error/invalid_server_preference.rb +24 -3
- data/lib/mongo/error/unsupported_collation.rb +51 -0
- data/lib/mongo/index/view.rb +28 -15
- data/lib/mongo/operation.rb +6 -0
- data/lib/mongo/operation/commands.rb +3 -0
- data/lib/mongo/operation/commands/aggregate.rb +10 -10
- data/lib/mongo/operation/commands/create.rb +45 -0
- data/lib/mongo/operation/commands/drop.rb +45 -0
- data/lib/mongo/operation/commands/drop_database.rb +45 -0
- data/lib/mongo/operation/commands/map_reduce.rb +12 -1
- data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
- data/lib/mongo/operation/read_preference.rb +9 -9
- data/lib/mongo/operation/specifiable.rb +34 -0
- data/lib/mongo/operation/takes_write_concern.rb +35 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +6 -0
- data/lib/mongo/operation/write/command/drop_index.rb +6 -0
- data/lib/mongo/operation/write/command/insert.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -0
- data/lib/mongo/operation/write/command/writable.rb +2 -2
- data/lib/mongo/operation/write/create_index.rb +2 -2
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +5 -1
- data/lib/mongo/operation/write/gle.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +2 -2
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +5 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -2
- data/lib/mongo/protocol/insert.rb +1 -2
- data/lib/mongo/protocol/query.rb +3 -7
- data/lib/mongo/server.rb +8 -3
- data/lib/mongo/server/connection.rb +17 -11
- data/lib/mongo/server/description.rb +22 -0
- data/lib/mongo/server/description/features.rb +2 -0
- data/lib/mongo/server/monitor.rb +5 -0
- data/lib/mongo/server/monitor/connection.rb +11 -0
- data/lib/mongo/server_selector/nearest.rb +9 -6
- data/lib/mongo/server_selector/primary.rb +4 -0
- data/lib/mongo/server_selector/primary_preferred.rb +7 -1
- data/lib/mongo/server_selector/secondary.rb +5 -0
- data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
- data/lib/mongo/server_selector/selectable.rb +57 -10
- data/lib/mongo/socket/ssl.rb +1 -0
- data/lib/mongo/uri.rb +4 -0
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +1 -0
- data/mongo.gemspec +1 -1
- data/spec/mongo/auth/cr_spec.rb +7 -1
- data/spec/mongo/auth/ldap_spec.rb +7 -1
- data/spec/mongo/auth/scram_spec.rb +7 -1
- data/spec/mongo/auth/x509_spec.rb +7 -1
- data/spec/mongo/bulk_write_spec.rb +598 -5
- data/spec/mongo/client_spec.rb +47 -1
- data/spec/mongo/cluster/app_metadata_spec.rb +104 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +14 -8
- data/spec/mongo/cluster/topology/sharded_spec.rb +9 -3
- data/spec/mongo/cluster/topology/single_spec.rb +10 -4
- data/spec/mongo/cluster_spec.rb +29 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +139 -0
- data/spec/mongo/collection/view/builder/find_command_spec.rb +6 -243
- data/spec/mongo/collection/view/map_reduce_spec.rb +104 -0
- data/spec/mongo/collection/view/readable_spec.rb +83 -0
- data/spec/mongo/collection/view/writable_spec.rb +447 -1
- data/spec/mongo/collection/view_spec.rb +57 -0
- data/spec/mongo/collection_spec.rb +926 -101
- data/spec/mongo/crud_spec.rb +4 -5
- data/spec/mongo/database_spec.rb +99 -1
- data/spec/mongo/index/view_spec.rb +360 -31
- data/spec/mongo/max_staleness_spec.rb +108 -0
- data/spec/mongo/operation/read_preference_spec.rb +8 -8
- data/spec/mongo/operation/write/command/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/command/insert_spec.rb +1 -1
- data/spec/mongo/operation/write/command/update_spec.rb +1 -1
- data/spec/mongo/server/connection_pool_spec.rb +3 -1
- data/spec/mongo/server/connection_spec.rb +17 -7
- data/spec/mongo/server/description/features_spec.rb +50 -0
- data/spec/mongo/server/description_spec.rb +9 -3
- data/spec/mongo/server_selection_spec.rb +5 -3
- data/spec/mongo/server_selector/nearest_spec.rb +73 -0
- data/spec/mongo/server_selector/primary_preferred_spec.rb +73 -0
- data/spec/mongo/server_selector/primary_spec.rb +36 -0
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +73 -0
- data/spec/mongo/server_selector/secondary_spec.rb +73 -0
- data/spec/mongo/server_selector_spec.rb +53 -0
- data/spec/mongo/server_spec.rb +3 -1
- data/spec/mongo/uri_spec.rb +54 -0
- data/spec/mongo/write_concern_spec.rb +18 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/authorization.rb +8 -1
- data/spec/support/crud.rb +15 -0
- data/spec/support/crud/read.rb +27 -19
- data/spec/support/crud/write.rb +28 -3
- data/spec/support/crud_tests/read/aggregate.yml +15 -3
- data/spec/support/crud_tests/read/count.yml +14 -3
- data/spec/support/crud_tests/read/distinct.yml +13 -1
- data/spec/support/crud_tests/read/find.yml +12 -2
- data/spec/support/crud_tests/write/deleteMany.yml +22 -1
- data/spec/support/crud_tests/write/deleteOne.yml +20 -1
- data/spec/support/crud_tests/write/findOneAndDelete.yml +27 -2
- data/spec/support/crud_tests/write/findOneAndReplace.yml +43 -14
- data/spec/support/crud_tests/write/findOneAndUpdate.yml +50 -8
- data/spec/support/crud_tests/write/replaceOne.yml +34 -10
- data/spec/support/crud_tests/write/updateMany.yml +42 -11
- data/spec/support/crud_tests/write/updateOne.yml +32 -7
- data/spec/support/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +36 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +51 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +51 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +35 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +23 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +36 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +59 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +43 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +59 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +43 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.yml +29 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.yml +29 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +27 -0
- data/spec/support/max_staleness/Sharded/Incompatible.yml +25 -0
- data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +20 -0
- data/spec/support/max_staleness/Single/Incompatible.yml +18 -0
- data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +20 -0
- data/spec/support/server_selection.rb +25 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +34 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +28 -0
- data/spec/support/shared/server_selector.rb +4 -3
- metadata +91 -6
- metadata.gz.sig +0 -0
@@ -41,7 +41,18 @@ module Mongo
|
|
41
41
|
# option spec :options [ Hash ] Options for the map reduce command.
|
42
42
|
#
|
43
43
|
# @since 2.0.0
|
44
|
-
class MapReduce < Command
|
44
|
+
class MapReduce < Command
|
45
|
+
include TakesWriteConcern
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def message(server)
|
50
|
+
sel = update_selector_for_read_pref(selector, server)
|
51
|
+
sel = update_selector_for_write_concern(sel, server)
|
52
|
+
opts = update_options_for_slave_ok(options, server)
|
53
|
+
Protocol::Query.new(db_name, query_coll, sel, opts)
|
54
|
+
end
|
55
|
+
end
|
45
56
|
end
|
46
57
|
end
|
47
58
|
end
|
@@ -28,12 +28,12 @@ module Mongo
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def
|
31
|
+
def update_selector_for_read_pref(sel, server)
|
32
32
|
if server.mongos? && read_pref = read.to_mongos
|
33
|
-
sel =
|
33
|
+
sel = sel[:$query] ? sel : { :$query => sel }
|
34
34
|
sel.merge(:$readPreference => read_pref)
|
35
35
|
else
|
36
|
-
|
36
|
+
sel
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -41,19 +41,19 @@ module Mongo
|
|
41
41
|
(server.cluster.single? && !server.mongos?) || read.slave_ok?
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def update_options_for_slave_ok(opts, server)
|
45
45
|
if slave_ok?(server)
|
46
|
-
|
47
|
-
(
|
46
|
+
opts.dup.tap do |o|
|
47
|
+
(o[:flags] ||= []) << SLAVE_OK
|
48
48
|
end
|
49
49
|
else
|
50
|
-
|
50
|
+
opts
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
def message(server)
|
55
|
-
sel =
|
56
|
-
opts =
|
55
|
+
sel = update_selector_for_read_pref(selector, server)
|
56
|
+
opts = update_options_for_slave_ok(options, server)
|
57
57
|
Protocol::Query.new(db_name, query_coll, sel, opts)
|
58
58
|
end
|
59
59
|
end
|
@@ -91,6 +91,11 @@ module Mongo
|
|
91
91
|
# @since 2.2.0
|
92
92
|
READ_CONCERN = :read_concern.freeze
|
93
93
|
|
94
|
+
# The max time ms option.
|
95
|
+
#
|
96
|
+
# @since 2.2.5
|
97
|
+
MAX_TIME_MS = :max_time_ms.freeze
|
98
|
+
|
94
99
|
# The field for a selector.
|
95
100
|
#
|
96
101
|
# @since 2.0.0
|
@@ -136,6 +141,11 @@ module Mongo
|
|
136
141
|
# @since 2.2.0
|
137
142
|
BYPASS_DOC_VALIDATION = :bypass_document_validation.freeze
|
138
143
|
|
144
|
+
# A collation to apply to the operation.
|
145
|
+
#
|
146
|
+
# @since 2.4.0
|
147
|
+
COLLATION = :collation.freeze
|
148
|
+
|
139
149
|
# @return [ Hash ] spec The specification for the operation.
|
140
150
|
attr_reader :spec
|
141
151
|
|
@@ -339,6 +349,18 @@ module Mongo
|
|
339
349
|
spec[READ_CONCERN]
|
340
350
|
end
|
341
351
|
|
352
|
+
# Get the max time ms value from the spec.
|
353
|
+
#
|
354
|
+
# @example Get the max time ms.
|
355
|
+
# specifiable.max_time_ms
|
356
|
+
#
|
357
|
+
# @return [ Hash ] The max time ms value.
|
358
|
+
#
|
359
|
+
# @since 2.2.5
|
360
|
+
def max_time_ms
|
361
|
+
spec[MAX_TIME_MS]
|
362
|
+
end
|
363
|
+
|
342
364
|
# Whether or not to bypass document level validation.
|
343
365
|
#
|
344
366
|
# @example Get the bypass_document_validation option.
|
@@ -351,6 +373,18 @@ module Mongo
|
|
351
373
|
spec[BYPASS_DOC_VALIDATION]
|
352
374
|
end
|
353
375
|
|
376
|
+
# The collation to apply to the operation.
|
377
|
+
#
|
378
|
+
# @example Get the collation option.
|
379
|
+
# specifiable.collation.
|
380
|
+
#
|
381
|
+
# @return [ Hash ] The collation document.
|
382
|
+
#
|
383
|
+
# @since 2.4.0
|
384
|
+
def collation
|
385
|
+
spec[COLLATION]
|
386
|
+
end
|
387
|
+
|
354
388
|
# The selector for from the specification.
|
355
389
|
#
|
356
390
|
# @example Get a selector specification.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright (C) 2014-2016 MongoDB, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Mongo
|
16
|
+
module Operation
|
17
|
+
|
18
|
+
# Adds behaviour for updating the selector for operations
|
19
|
+
# that may take a write concern.
|
20
|
+
#
|
21
|
+
# @since 2.4.0
|
22
|
+
module TakesWriteConcern
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def update_selector_for_write_concern(sel, server)
|
27
|
+
if write_concern && server.features.collation_enabled?
|
28
|
+
sel.merge(writeConcern: write_concern.options)
|
29
|
+
else
|
30
|
+
sel
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -65,7 +65,7 @@ module Mongo
|
|
65
65
|
def gle
|
66
66
|
wc = write_concern || WriteConcern.get(WriteConcern::DEFAULT)
|
67
67
|
gle_message = ( ordered? && wc.get_last_error.nil? ) ?
|
68
|
-
|
68
|
+
WriteConcern.get(WriteConcern::DEFAULT).get_last_error :
|
69
69
|
wc.get_last_error
|
70
70
|
if gle_message
|
71
71
|
Protocol::Query.new(
|
@@ -30,6 +30,7 @@ module Mongo
|
|
30
30
|
class CreateIndex
|
31
31
|
include Specifiable
|
32
32
|
include Writable
|
33
|
+
include TakesWriteConcern
|
33
34
|
|
34
35
|
private
|
35
36
|
|
@@ -41,6 +42,11 @@ module Mongo
|
|
41
42
|
def selector
|
42
43
|
{ :createIndexes => coll_name, :indexes => indexes }
|
43
44
|
end
|
45
|
+
|
46
|
+
def message(server)
|
47
|
+
sel = update_selector_for_write_concern(selector, server)
|
48
|
+
Protocol::Query.new(db_name, Database::COMMAND, sel, options)
|
49
|
+
end
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
@@ -31,6 +31,7 @@ module Mongo
|
|
31
31
|
class DropIndex
|
32
32
|
include Specifiable
|
33
33
|
include Writable
|
34
|
+
include TakesWriteConcern
|
34
35
|
|
35
36
|
private
|
36
37
|
|
@@ -42,6 +43,11 @@ module Mongo
|
|
42
43
|
def selector
|
43
44
|
{ :dropIndexes => coll_name, :index => index_name }
|
44
45
|
end
|
46
|
+
|
47
|
+
def message(server)
|
48
|
+
sel = update_selector_for_write_concern(selector, server)
|
49
|
+
Protocol::Query.new(db_name, Database::COMMAND, sel, options)
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
@@ -36,7 +36,7 @@ module Mongo
|
|
36
36
|
# @since 2.0.0
|
37
37
|
def execute(server)
|
38
38
|
server.with_connection do |connection|
|
39
|
-
connection.dispatch([ message ], operation_id)
|
39
|
+
connection.dispatch([ message(server) ], operation_id)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -47,7 +47,7 @@ module Mongo
|
|
47
47
|
# @return [ Mongo::Protocol::Query ] Wire protocol message.
|
48
48
|
#
|
49
49
|
# @since 2.0.0
|
50
|
-
def message
|
50
|
+
def message(server)
|
51
51
|
Protocol::Query.new(db_name, Database::COMMAND, selector, options)
|
52
52
|
end
|
53
53
|
end
|
@@ -60,7 +60,11 @@ module Mongo
|
|
60
60
|
Command::Delete.new(s)
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def has_collation?
|
64
|
+
delete[:collation]
|
65
|
+
end
|
66
|
+
|
67
|
+
def message(server)
|
64
68
|
selector = delete[Operation::Q]
|
65
69
|
opts = (delete[Operation::LIMIT] || 0) <= 0 ? {} : { :flags => [ :single_remove ] }
|
66
70
|
Protocol::Delete.new(db_name, coll_name, selector, opts)
|
@@ -28,7 +28,7 @@ module Mongo
|
|
28
28
|
server.with_connection do |connection|
|
29
29
|
result_class = self.class.const_defined?(:LegacyResult, false) ? self.class::LegacyResult :
|
30
30
|
self.class.const_defined?(:Result, false) ? self.class::Result : Result
|
31
|
-
result_class.new(connection.dispatch([ message, gle ].compact)).validate!
|
31
|
+
result_class.new(connection.dispatch([ message(server), gle ].compact)).validate!
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -57,11 +57,11 @@ module Mongo
|
|
57
57
|
|
58
58
|
def execute_message(server)
|
59
59
|
server.with_connection do |connection|
|
60
|
-
Result.new(connection.dispatch([ message, gle ].compact), @ids).validate!
|
60
|
+
Result.new(connection.dispatch([ message(server), gle ].compact), @ids).validate!
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def message
|
64
|
+
def message(server)
|
65
65
|
opts = !!options[:continue_on_error] ? { :flags => [:continue_on_error] } : {}
|
66
66
|
Protocol::Insert.new(db_name, coll_name, ensure_ids(documents), opts)
|
67
67
|
end
|
@@ -63,7 +63,11 @@ module Mongo
|
|
63
63
|
Command::Update.new(s)
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def has_collation?
|
67
|
+
update[:collation]
|
68
|
+
end
|
69
|
+
|
70
|
+
def message(server)
|
67
71
|
flags = []
|
68
72
|
flags << :multi_update if update[Operation::MULTI]
|
69
73
|
flags << :upsert if update[Operation::UPSERT]
|
@@ -34,8 +34,8 @@ module Mongo
|
|
34
34
|
#
|
35
35
|
# @since 2.1.0
|
36
36
|
def execute(server)
|
37
|
-
if !server.features.write_command_enabled? ||
|
38
|
-
|
37
|
+
if !server.features.write_command_enabled? || unacknowledged_write?
|
38
|
+
raise Error::UnsupportedCollation.new(Error::UnsupportedCollation::UNACKNOWLEDGED_WRITES_MESSAGE) if has_collation?
|
39
39
|
execute_message(server)
|
40
40
|
else
|
41
41
|
execute_write_command(server)
|
@@ -44,6 +44,14 @@ module Mongo
|
|
44
44
|
|
45
45
|
private
|
46
46
|
|
47
|
+
def has_collation?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def unacknowledged_write?
|
52
|
+
write_concern && write_concern.get_last_error.nil?
|
53
|
+
end
|
54
|
+
|
47
55
|
def execute_write_command(server)
|
48
56
|
result_class = self.class.const_defined?(:Result, false) ? self.class::Result : Result
|
49
57
|
result_class.new(write_command_op.execute(server)).validate!
|
@@ -54,7 +54,6 @@ module Mongo
|
|
54
54
|
@documents = documents
|
55
55
|
@flags = options[:flags] || []
|
56
56
|
@upconverter = Upconverter.new(collection, documents, options)
|
57
|
-
@options = options
|
58
57
|
end
|
59
58
|
|
60
59
|
# Return the event payload for monitoring.
|
@@ -77,7 +76,7 @@ module Mongo
|
|
77
76
|
private
|
78
77
|
|
79
78
|
def validating_keys?
|
80
|
-
|
79
|
+
true
|
81
80
|
end
|
82
81
|
|
83
82
|
attr_reader :upconverter
|
data/lib/mongo/protocol/query.rb
CHANGED
@@ -252,7 +252,7 @@ module Mongo
|
|
252
252
|
#
|
253
253
|
# @since 2.1.0
|
254
254
|
def command_name
|
255
|
-
|
255
|
+
command? ? filter.keys.first : FIND
|
256
256
|
end
|
257
257
|
|
258
258
|
private
|
@@ -261,13 +261,9 @@ module Mongo
|
|
261
261
|
collection == Database::COMMAND
|
262
262
|
end
|
263
263
|
|
264
|
-
def query_filter
|
265
|
-
filter[:$query] || filter
|
266
|
-
end
|
267
|
-
|
268
264
|
def op_command
|
269
265
|
document = BSON::Document.new
|
270
|
-
|
266
|
+
filter.each do |field, value|
|
271
267
|
document.store(field.to_s, value)
|
272
268
|
end
|
273
269
|
document
|
@@ -276,7 +272,7 @@ module Mongo
|
|
276
272
|
def find_command
|
277
273
|
document = BSON::Document.new
|
278
274
|
document.store(FIND, collection)
|
279
|
-
document.store(FILTER,
|
275
|
+
document.store(FILTER, filter[:$query] ? filter[:$query] : filter)
|
280
276
|
OPTION_MAPPINGS.each do |legacy, option|
|
281
277
|
document.store(option, options[legacy]) unless options[legacy].nil?
|
282
278
|
end
|
data/lib/mongo/server.rb
CHANGED
@@ -44,7 +44,7 @@ module Mongo
|
|
44
44
|
attr_reader :monitoring
|
45
45
|
|
46
46
|
# Get the description from the monitor and scan on monitor.
|
47
|
-
def_delegators :monitor, :description, :scan
|
47
|
+
def_delegators :monitor, :description, :scan!, :heartbeat_frequency, :last_scan
|
48
48
|
|
49
49
|
# Delegate convenience methods to the monitor description.
|
50
50
|
def_delegators :description,
|
@@ -64,7 +64,12 @@ module Mongo
|
|
64
64
|
:secondary?,
|
65
65
|
:standalone?,
|
66
66
|
:unknown?,
|
67
|
-
:unknown
|
67
|
+
:unknown!,
|
68
|
+
:last_write_date
|
69
|
+
|
70
|
+
# Get the app metadata from the cluster.
|
71
|
+
def_delegators :cluster,
|
72
|
+
:app_metadata
|
68
73
|
|
69
74
|
# Is this server equal to another?
|
70
75
|
#
|
@@ -158,7 +163,7 @@ module Mongo
|
|
158
163
|
@cluster = cluster
|
159
164
|
@monitoring = monitoring
|
160
165
|
@options = options.freeze
|
161
|
-
@monitor = Monitor.new(address, event_listeners, options)
|
166
|
+
@monitor = Monitor.new(address, event_listeners, options.merge(app_metadata: cluster.app_metadata))
|
162
167
|
monitor.scan!
|
163
168
|
monitor.run!
|
164
169
|
ObjectSpace.define_finalizer(self, self.class.finalize(monitor))
|