mongo 2.3.1 → 2.4.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 +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
data/spec/mongo/server_spec.rb
CHANGED
data/spec/mongo/uri_spec.rb
CHANGED
@@ -538,6 +538,52 @@ describe Mongo::URI do
|
|
538
538
|
end
|
539
539
|
end
|
540
540
|
|
541
|
+
context 'read preference max staleness option provided' do
|
542
|
+
|
543
|
+
let(:options) do
|
544
|
+
'readPreference=Secondary&maxStalenessMS=120000'
|
545
|
+
end
|
546
|
+
|
547
|
+
let(:read) do
|
548
|
+
Mongo::Options::Redacted.new(mode: :secondary, :max_staleness => 120)
|
549
|
+
end
|
550
|
+
|
551
|
+
it 'sets the read preference max staleness in seconds' do
|
552
|
+
expect(uri.uri_options[:read]).to eq(read)
|
553
|
+
end
|
554
|
+
|
555
|
+
it 'sets the options on a client created with the uri' do
|
556
|
+
expect(Mongo::Client.new(string).options[:read]).to eq(read)
|
557
|
+
end
|
558
|
+
|
559
|
+
context 'when the read preference and max staleness combination is invalid' do
|
560
|
+
|
561
|
+
context 'when max staleness is combined with read preference mode primary' do
|
562
|
+
|
563
|
+
let(:options) do
|
564
|
+
'readPreference=primary&maxStalenessMS=120000'
|
565
|
+
end
|
566
|
+
|
567
|
+
it 'raises an exception when read preference is accessed on the client' do
|
568
|
+
expect {
|
569
|
+
Mongo::Client.new(string).read_preference
|
570
|
+
}.to raise_exception(Mongo::Error::InvalidServerPreference)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
context 'when the max staleness value is not at least twice heartbeat frequency' do
|
575
|
+
|
576
|
+
let(:options) do
|
577
|
+
'readPreference=secondary&maxStalenessMS=1'
|
578
|
+
end
|
579
|
+
|
580
|
+
it 'does not raise an exception until the read preference is used' do
|
581
|
+
expect(Mongo::Client.new(string).read_preference).to be_a(Mongo::ServerSelector::Secondary)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
541
587
|
context 'replica set option provided' do
|
542
588
|
let(:rs_name) { TEST_SET }
|
543
589
|
let(:options) { "replicaSet=#{rs_name}" }
|
@@ -850,5 +896,13 @@ describe Mongo::URI do
|
|
850
896
|
end
|
851
897
|
end
|
852
898
|
end
|
899
|
+
|
900
|
+
context 'when an app name option is provided' do
|
901
|
+
let(:options) { "appname=reports" }
|
902
|
+
|
903
|
+
it 'sets the app name on the client' do
|
904
|
+
expect(Mongo::Client.new(string).options[:app_name]).to eq(:reports)
|
905
|
+
end
|
906
|
+
end
|
853
907
|
end
|
854
908
|
end
|
@@ -15,6 +15,24 @@ describe Mongo::WriteConcern do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
context 'when the value is a WriteConcern object' do
|
19
|
+
|
20
|
+
let(:value) do
|
21
|
+
Mongo::WriteConcern.get({})
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the object' do
|
25
|
+
expect(Mongo::WriteConcern.get(value)).to be(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when the value is nil' do
|
30
|
+
|
31
|
+
it 'returns nil' do
|
32
|
+
expect(Mongo::WriteConcern.get(nil)).to be(nil)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
18
36
|
context 'when w is 0' do
|
19
37
|
|
20
38
|
context 'when no other options are provided' do
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
|
|
4
4
|
SERVER_DISCOVERY_TESTS = Dir.glob("#{CURRENT_PATH}/support/sdam/**/*.yml")
|
5
5
|
SERVER_SELECTION_RTT_TESTS = Dir.glob("#{CURRENT_PATH}/support/server_selection/rtt/*.yml")
|
6
6
|
SERVER_SELECTION_TESTS = Dir.glob("#{CURRENT_PATH}/support/server_selection/selection/**/*.yml")
|
7
|
+
MAX_STALENESS_TESTS = Dir.glob("#{CURRENT_PATH}/support/max_staleness/**/*.yml")
|
7
8
|
CRUD_TESTS = Dir.glob("#{CURRENT_PATH}/support/crud_tests/**/*.yml")
|
8
9
|
COMMAND_MONITORING_TESTS = Dir.glob("#{CURRENT_PATH}/support/command_monitoring/**/*.yml")
|
9
10
|
CONNECTION_STRING_TESTS = Dir.glob("#{CURRENT_PATH}/support/connection_string_tests/*.yml")
|
@@ -119,6 +120,15 @@ def single_seed?
|
|
119
120
|
ADDRESSES.size == 1
|
120
121
|
end
|
121
122
|
|
123
|
+
# For instances where behaviour is different on different versions, we need to
|
124
|
+
# determine in the specs if we are 3.4 or higher.
|
125
|
+
#
|
126
|
+
# @since 2.4.0
|
127
|
+
def collation_enabled?
|
128
|
+
$mongo_client ||= initialize_scanned_client!
|
129
|
+
$collation_enabled ||= $mongo_client.cluster.servers.first.features.collation_enabled?
|
130
|
+
end
|
131
|
+
|
122
132
|
# For instances where behaviour is different on different versions, we need to
|
123
133
|
# determine in the specs if we are 3.2 or higher.
|
124
134
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-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.
|
@@ -249,5 +249,12 @@ module Authorization
|
|
249
249
|
context.let(:default_address) do
|
250
250
|
authorized_client.cluster.next_primary.address
|
251
251
|
end
|
252
|
+
|
253
|
+
# Get a default app metadata.
|
254
|
+
#
|
255
|
+
# @since 2.4.0
|
256
|
+
context.let(:app_metadata) do
|
257
|
+
authorized_client.cluster.app_metadata
|
258
|
+
end
|
252
259
|
end
|
253
260
|
end
|
data/spec/support/crud.rb
CHANGED
@@ -169,6 +169,21 @@ module Mongo
|
|
169
169
|
!write_command_enabled && @operation.requires_2_6?(collection)
|
170
170
|
end
|
171
171
|
|
172
|
+
# Whether this operation requires a certain server version to be run.
|
173
|
+
#
|
174
|
+
# @example Determine whether this operation requires a certain server feature.
|
175
|
+
# operation.feature_enabled?(collection)
|
176
|
+
#
|
177
|
+
# @param [ Collection ] collection The collection the operation
|
178
|
+
# should be executed on.
|
179
|
+
#
|
180
|
+
# @return [ true, false ] Whether this operation requires a certain server version.
|
181
|
+
#
|
182
|
+
# @since 2.4.0
|
183
|
+
def feature_enabled?(collection)
|
184
|
+
@operation.feature_enabled?(collection)
|
185
|
+
end
|
186
|
+
|
172
187
|
private
|
173
188
|
|
174
189
|
def outcome_collection_data
|
data/spec/support/crud/read.rb
CHANGED
@@ -28,19 +28,10 @@ module Mongo
|
|
28
28
|
ARGUMENT_MAP = { :sort => 'sort',
|
29
29
|
:skip => 'skip',
|
30
30
|
:batch_size => 'batchSize',
|
31
|
-
:limit => 'limit'
|
31
|
+
:limit => 'limit',
|
32
|
+
:collation => 'collation'
|
32
33
|
}
|
33
34
|
|
34
|
-
# Map of read preference mode names to their equivalent Ruby-formatted symbols.
|
35
|
-
#
|
36
|
-
# @since 2.4.0
|
37
|
-
READ_PREFERENCE_MAP = { 'primary' => :primary,
|
38
|
-
'secondary' => :secondary,
|
39
|
-
'primaryPreferred' => :primary_preferred,
|
40
|
-
'secondaryPreferred' => :secondary_preferred,
|
41
|
-
'nearest' => :nearest
|
42
|
-
}
|
43
|
-
|
44
35
|
# The operation name.
|
45
36
|
#
|
46
37
|
# @return [ String ] name The operation name.
|
@@ -100,6 +91,26 @@ module Mongo
|
|
100
91
|
name == 'aggregate' && pipeline.find {|op| op.keys.include?('$out') }
|
101
92
|
end
|
102
93
|
|
94
|
+
# Whether this operation requires a certain server version to be run.
|
95
|
+
#
|
96
|
+
# @example Determine whether this operation requires a certain server feature.
|
97
|
+
# operation.feature_enabled?(collection)
|
98
|
+
#
|
99
|
+
# @param [ Collection ] collection The collection the operation
|
100
|
+
# should be executed on.
|
101
|
+
#
|
102
|
+
# @return [ true, false ] Whether this operation requires a certain server version.
|
103
|
+
#
|
104
|
+
# @since 2.4.0
|
105
|
+
def feature_enabled?(collection)
|
106
|
+
if collation
|
107
|
+
return $mongo_client.cluster.servers.first.features.collation_enabled?
|
108
|
+
elsif requires_2_6?(collection)
|
109
|
+
return $mongo_client.cluster.servers.first.features.write_command_enabled?
|
110
|
+
end
|
111
|
+
true
|
112
|
+
end
|
113
|
+
|
103
114
|
private
|
104
115
|
|
105
116
|
def count(collection)
|
@@ -119,8 +130,7 @@ module Mongo
|
|
119
130
|
end
|
120
131
|
|
121
132
|
def find(collection)
|
122
|
-
|
123
|
-
(read_preference ? collection.with(read: read_preference) : collection).find(filter, opts).to_a
|
133
|
+
collection.find(filter, options.merge(modifiers: BSON::Document.new(modifiers) || {})).to_a
|
124
134
|
end
|
125
135
|
|
126
136
|
def options
|
@@ -129,6 +139,10 @@ module Mongo
|
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
142
|
+
def collation
|
143
|
+
arguments['collation']
|
144
|
+
end
|
145
|
+
|
132
146
|
def batch_size
|
133
147
|
arguments['batchSize']
|
134
148
|
end
|
@@ -152,12 +166,6 @@ module Mongo
|
|
152
166
|
def arguments
|
153
167
|
@spec['arguments']
|
154
168
|
end
|
155
|
-
|
156
|
-
def read_preference
|
157
|
-
if @spec['read_preference'] && @spec['read_preference']['mode']
|
158
|
-
{ mode: READ_PREFERENCE_MAP[@spec['read_preference']['mode']] }
|
159
|
-
end
|
160
|
-
end
|
161
169
|
end
|
162
170
|
end
|
163
171
|
end
|
data/spec/support/crud/write.rb
CHANGED
@@ -47,7 +47,8 @@ module Mongo
|
|
47
47
|
:return_document => 'returnDocument',
|
48
48
|
:upsert => 'upsert',
|
49
49
|
:ordered => 'ordered',
|
50
|
-
:write_concern => 'writeConcern'
|
50
|
+
:write_concern => 'writeConcern',
|
51
|
+
:collation => 'collation'
|
51
52
|
}
|
52
53
|
|
53
54
|
# Operations that need a check if results on < 2.6 will match.
|
@@ -113,6 +114,26 @@ module Mongo
|
|
113
114
|
REQUIRES_2_6.include?(name) && upsert
|
114
115
|
end
|
115
116
|
|
117
|
+
# Whether this operation requires a certain server version to be run.
|
118
|
+
#
|
119
|
+
# @example Determine whether this operation requires a certain server feature.
|
120
|
+
# operation.feature_enabled?(collection)
|
121
|
+
#
|
122
|
+
# @param [ Collection ] collection The collection the operation
|
123
|
+
# should be executed on.
|
124
|
+
#
|
125
|
+
# @return [ true, false ] Whether this operation requires a certain server version.
|
126
|
+
#
|
127
|
+
# @since 2.4.0
|
128
|
+
def feature_enabled?(collection)
|
129
|
+
if collation
|
130
|
+
return $mongo_client.cluster.servers.first.features.collation_enabled?
|
131
|
+
elsif requires_2_6?(collection)
|
132
|
+
return $mongo_client.cluster.servers.first.features.write_command_enabled?
|
133
|
+
end
|
134
|
+
true
|
135
|
+
end
|
136
|
+
|
116
137
|
private
|
117
138
|
|
118
139
|
def bulk_write(collection)
|
@@ -120,12 +141,12 @@ module Mongo
|
|
120
141
|
end
|
121
142
|
|
122
143
|
def delete_many(collection)
|
123
|
-
result = collection.delete_many(filter)
|
144
|
+
result = collection.delete_many(filter, options)
|
124
145
|
{ 'deletedCount' => result.deleted_count }
|
125
146
|
end
|
126
147
|
|
127
148
|
def delete_one(collection)
|
128
|
-
result = collection.delete_one(filter)
|
149
|
+
result = collection.delete_one(filter, options)
|
129
150
|
{ 'deletedCount' => result.deleted_count }
|
130
151
|
end
|
131
152
|
|
@@ -178,6 +199,10 @@ module Mongo
|
|
178
199
|
end
|
179
200
|
end
|
180
201
|
|
202
|
+
def collation
|
203
|
+
arguments['collation']
|
204
|
+
end
|
205
|
+
|
181
206
|
def replacement
|
182
207
|
arguments['replacement']
|
183
208
|
end
|
@@ -2,6 +2,7 @@ data:
|
|
2
2
|
- {_id: 1, x: 11}
|
3
3
|
- {_id: 2, x: 22}
|
4
4
|
- {_id: 3, x: 33}
|
5
|
+
- {_id: 4, x: 'ping'}
|
5
6
|
|
6
7
|
tests:
|
7
8
|
-
|
@@ -12,7 +13,7 @@ tests:
|
|
12
13
|
pipeline:
|
13
14
|
- $sort: {x: 1}
|
14
15
|
- $match:
|
15
|
-
_id: {$gt: 1}
|
16
|
+
_id: {$gt: 1, $lt: 4}
|
16
17
|
batchSize: 2
|
17
18
|
|
18
19
|
outcome:
|
@@ -27,7 +28,7 @@ tests:
|
|
27
28
|
pipeline:
|
28
29
|
- $sort: {x: 1}
|
29
30
|
- $match:
|
30
|
-
_id: {$gt: 1}
|
31
|
+
_id: {$gt: 1, $lt: 4}
|
31
32
|
- $out: "other_test_collection"
|
32
33
|
batchSize: 2
|
33
34
|
|
@@ -40,4 +41,15 @@ tests:
|
|
40
41
|
data:
|
41
42
|
- {_id: 2, x: 22}
|
42
43
|
- {_id: 3, x: 33}
|
43
|
-
|
44
|
+
-
|
45
|
+
description: "Aggregate with collation"
|
46
|
+
operation:
|
47
|
+
name: aggregate
|
48
|
+
arguments:
|
49
|
+
pipeline:
|
50
|
+
- $match:
|
51
|
+
x: 'PING'
|
52
|
+
collation: { locale: 'en_US', strength: 2 }
|
53
|
+
outcome:
|
54
|
+
result:
|
55
|
+
- {_id: 4, x: 'ping'}
|
@@ -2,6 +2,7 @@ data:
|
|
2
2
|
- {_id: 1, x: 11}
|
3
3
|
- {_id: 2, x: 22}
|
4
4
|
- {_id: 3, x: 33}
|
5
|
+
- {_id: 4, x: 'PING'}
|
5
6
|
|
6
7
|
tests:
|
7
8
|
-
|
@@ -12,14 +13,14 @@ tests:
|
|
12
13
|
filter: { }
|
13
14
|
|
14
15
|
outcome:
|
15
|
-
result:
|
16
|
+
result: 4
|
16
17
|
-
|
17
18
|
description: "Count with a filter"
|
18
19
|
operation:
|
19
20
|
name: count
|
20
21
|
arguments:
|
21
22
|
filter:
|
22
|
-
_id: {$gt: 1}
|
23
|
+
_id: {$gt: 1, $lt: 4}
|
23
24
|
|
24
25
|
outcome:
|
25
26
|
result: 2
|
@@ -33,5 +34,15 @@ tests:
|
|
33
34
|
limit: 3
|
34
35
|
|
35
36
|
outcome:
|
36
|
-
result:
|
37
|
+
result: 3
|
38
|
+
-
|
39
|
+
description: "Count with collation"
|
40
|
+
operation:
|
41
|
+
name: count
|
42
|
+
arguments:
|
43
|
+
filter: { x: 'ping' }
|
44
|
+
collation: { locale: 'en_US', strength: 2 }
|
45
|
+
|
46
|
+
outcome:
|
47
|
+
result: 1
|
37
48
|
|
@@ -2,6 +2,8 @@ data:
|
|
2
2
|
- {_id: 1, x: 11}
|
3
3
|
- {_id: 2, x: 22}
|
4
4
|
- {_id: 3, x: 33}
|
5
|
+
- {_id: 4, string: 'PING'}
|
6
|
+
- {_id: 5, string: 'ping'}
|
5
7
|
|
6
8
|
tests:
|
7
9
|
-
|
@@ -30,4 +32,14 @@ tests:
|
|
30
32
|
result:
|
31
33
|
- 22
|
32
34
|
- 33
|
33
|
-
|
35
|
+
-
|
36
|
+
description: "Distinct with a collation"
|
37
|
+
operation:
|
38
|
+
name: distinct
|
39
|
+
arguments:
|
40
|
+
fieldName: "string"
|
41
|
+
collation: { locale: 'en_US', strength: 2 }
|
42
|
+
|
43
|
+
outcome:
|
44
|
+
result:
|
45
|
+
- 'PING'
|
@@ -4,6 +4,7 @@ data:
|
|
4
4
|
- {_id: 3, x: 33}
|
5
5
|
- {_id: 4, x: 44}
|
6
6
|
- {_id: 5, x: 55}
|
7
|
+
- {_id: 6, x: 'ping'}
|
7
8
|
|
8
9
|
tests:
|
9
10
|
-
|
@@ -23,7 +24,7 @@ tests:
|
|
23
24
|
name: "find"
|
24
25
|
arguments:
|
25
26
|
filter:
|
26
|
-
_id: {$gt: 2}
|
27
|
+
_id: {$gt: 2, $lt: 6}
|
27
28
|
sort: {_id: 1}
|
28
29
|
skip: 2
|
29
30
|
limit: 2
|
@@ -47,4 +48,13 @@ tests:
|
|
47
48
|
- {_id: 2, x: 22}
|
48
49
|
- {_id: 3, x: 33}
|
49
50
|
- {_id: 4, x: 44}
|
50
|
-
|
51
|
+
-
|
52
|
+
description: "Find with a collation"
|
53
|
+
operation:
|
54
|
+
name: "find"
|
55
|
+
arguments:
|
56
|
+
filter: {x: 'PING'}
|
57
|
+
collation: { locale: 'en_US', strength: 2 }
|
58
|
+
outcome:
|
59
|
+
result:
|
60
|
+
- {_id: 6, x: 'ping'}
|