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
@@ -25,8 +25,7 @@ module Mongo
|
|
25
25
|
# @return [ Cursor ] cursor The cursor.
|
26
26
|
attr_reader :cursor
|
27
27
|
|
28
|
-
def_delegators :@cursor, :collection_name, :database, :view
|
29
|
-
def_delegators :view, :batch_size
|
28
|
+
def_delegators :@cursor, :batch_size, :collection_name, :database, :view
|
30
29
|
|
31
30
|
# Create the new builder.
|
32
31
|
#
|
@@ -56,7 +55,7 @@ module Mongo
|
|
56
55
|
|
57
56
|
def get_more_command
|
58
57
|
command = { :getMore => cursor.id, :collection => collection_name }
|
59
|
-
command[:batchSize] = batch_size
|
58
|
+
command[:batchSize] = batch_size if batch_size
|
60
59
|
# If the max_await_time_ms option is set, then we set maxTimeMS on
|
61
60
|
# the get more command.
|
62
61
|
if view.respond_to?(:max_await_time_ms)
|
data/lib/mongo/database.rb
CHANGED
@@ -68,6 +68,10 @@ module Mongo
|
|
68
68
|
:read_preference,
|
69
69
|
:write_concern
|
70
70
|
|
71
|
+
# @return [ Mongo::Server ] Get the primary server from the cluster.
|
72
|
+
def_delegators :cluster,
|
73
|
+
:next_primary
|
74
|
+
|
71
75
|
# Check equality of the database object against another. Will simply check
|
72
76
|
# if the names are the same.
|
73
77
|
#
|
@@ -153,7 +157,6 @@ module Mongo
|
|
153
157
|
Operation::Commands::Command.new({
|
154
158
|
:selector => operation,
|
155
159
|
:db_name => name,
|
156
|
-
:options => { :limit => -1 },
|
157
160
|
:read => preference
|
158
161
|
}).execute(server)
|
159
162
|
end
|
@@ -167,7 +170,12 @@ module Mongo
|
|
167
170
|
#
|
168
171
|
# @since 2.0.0
|
169
172
|
def drop
|
170
|
-
|
173
|
+
operation = { :dropDatabase => 1 }
|
174
|
+
Operation::Commands::DropDatabase.new({
|
175
|
+
selector: operation,
|
176
|
+
db_name: name,
|
177
|
+
write_concern: write_concern
|
178
|
+
}).execute(next_primary)
|
171
179
|
end
|
172
180
|
|
173
181
|
# Instantiate a new database object.
|
data/lib/mongo/error.rb
CHANGED
@@ -83,6 +83,7 @@ require 'mongo/error/invalid_database_name'
|
|
83
83
|
require 'mongo/error/invalid_document'
|
84
84
|
require 'mongo/error/invalid_file'
|
85
85
|
require 'mongo/error/invalid_file_revision'
|
86
|
+
require 'mongo/error/invalid_application_name'
|
86
87
|
require 'mongo/error/invalid_nonce'
|
87
88
|
require 'mongo/error/invalid_replacement_document'
|
88
89
|
require 'mongo/error/invalid_server_preference'
|
@@ -101,4 +102,5 @@ require 'mongo/error/unchangeable_collection_option'
|
|
101
102
|
require 'mongo/error/unexpected_chunk_length'
|
102
103
|
require 'mongo/error/unexpected_response'
|
103
104
|
require 'mongo/error/missing_file_chunk'
|
105
|
+
require 'mongo/error/unsupported_collation'
|
104
106
|
require 'mongo/error/unsupported_features'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (C) 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
|
+
class Error
|
17
|
+
|
18
|
+
# This exception is raised when the metadata document sent to the server
|
19
|
+
# at the time of a connection handshake is invalid.
|
20
|
+
#
|
21
|
+
# @since 2.4.0
|
22
|
+
class InvalidApplicationName < Error
|
23
|
+
|
24
|
+
# Instantiate the new exception.
|
25
|
+
#
|
26
|
+
# @example Create the exception.
|
27
|
+
# InvalidApplicationName.new(app_name, 128)
|
28
|
+
#
|
29
|
+
# @param [ String ] app_name The application name option.
|
30
|
+
# @param [ Integer ] max_size The max byte size of the application name.
|
31
|
+
#
|
32
|
+
# @since 2.4.0
|
33
|
+
def initialize(app_name, max_size)
|
34
|
+
super("The provided application name '#{app_name}' cannot exceed #{max_size} bytes.")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -20,16 +20,37 @@ module Mongo
|
|
20
20
|
# @since 2.0.0
|
21
21
|
class InvalidServerPreference < Error
|
22
22
|
|
23
|
+
# Error message when tags are specified for a read preference that cannot support them.
|
24
|
+
#
|
25
|
+
# @since 2.4.0
|
26
|
+
NO_TAG_SUPPORT = 'This read preference cannot be combined with tags.'.freeze
|
27
|
+
|
28
|
+
# Error message when a max staleness is specified for a read preference that cannot support it.
|
29
|
+
#
|
30
|
+
# @since 2.4.0
|
31
|
+
NO_MAX_STALENESS_SUPPORT = 'max_staleness cannot be set for this read preference.'.freeze
|
32
|
+
|
33
|
+
# Error message for when the max staleness is not at least twice the heartbeat frequency.
|
34
|
+
#
|
35
|
+
# @since 2.4.0
|
36
|
+
INVALID_MAX_STALENESS = "max_staleness must be at least twice the client's heartbeat frequency.".freeze
|
37
|
+
|
38
|
+
# Error message when max staleness cannot be used because one or more servers has version < 3.4.
|
39
|
+
#
|
40
|
+
# @since 2.4.0
|
41
|
+
NO_MAX_STALENESS_WITH_LEGACY_SERVER = 'max_staleness can only be set for a cluster in which ' +
|
42
|
+
'each server is at least version 3.4.'.freeze
|
43
|
+
|
23
44
|
# Instantiate the new exception.
|
24
45
|
#
|
25
46
|
# @example Instantiate the exception.
|
26
|
-
# Mongo::
|
47
|
+
# Mongo::Error::InvalidServerPreference.new
|
27
48
|
#
|
28
49
|
# @param [ String ] name The preference name.
|
29
50
|
#
|
30
51
|
# @since 2.0.0
|
31
|
-
def initialize(
|
32
|
-
super(
|
52
|
+
def initialize(message)
|
53
|
+
super(message)
|
33
54
|
end
|
34
55
|
end
|
35
56
|
end
|
@@ -0,0 +1,51 @@
|
|
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
|
+
class Error
|
17
|
+
|
18
|
+
# Raised if a collation is specified for an operation but the server selected does not
|
19
|
+
# support collations.
|
20
|
+
#
|
21
|
+
# @since 2.4.0
|
22
|
+
class UnsupportedCollation < Error
|
23
|
+
|
24
|
+
# The default error message describing that collations is not supported.
|
25
|
+
#
|
26
|
+
# @return [ String ] A default message describing that collations is not supported by the server.
|
27
|
+
#
|
28
|
+
# @since 2.4.0
|
29
|
+
DEFAULT_MESSAGE = "Collations is not a supported feature of the server handling this operation. " +
|
30
|
+
"Operation results may be unexpected."
|
31
|
+
|
32
|
+
# The error message describing that collations cannot be used when write concern is unacknowledged.
|
33
|
+
#
|
34
|
+
# @return [ String ] A message describing that collations cannot be used when write concern is unacknowledged.
|
35
|
+
#
|
36
|
+
# @since 2.4.0
|
37
|
+
UNACKNOWLEDGED_WRITES_MESSAGE = "A collation cannot be specified when using unacknowledged writes. " +
|
38
|
+
"Either remove the collation option or use acknowledged writes (w >= 1)."
|
39
|
+
|
40
|
+
# Create the new exception.
|
41
|
+
#
|
42
|
+
# @example Create the new exception.
|
43
|
+
# Mongo::Error::UnsupportedCollation.new
|
44
|
+
#
|
45
|
+
# @since 2.4.0
|
46
|
+
def initialize(message = nil)
|
47
|
+
super(message || DEFAULT_MESSAGE)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/mongo/index/view.rb
CHANGED
@@ -29,7 +29,7 @@ module Mongo
|
|
29
29
|
# when sending the listIndexes command.
|
30
30
|
attr_reader :batch_size
|
31
31
|
|
32
|
-
def_delegators :@collection, :cluster, :database, :read_preference
|
32
|
+
def_delegators :@collection, :cluster, :database, :read_preference, :write_concern
|
33
33
|
def_delegators :cluster, :next_primary
|
34
34
|
|
35
35
|
# The index key field.
|
@@ -64,7 +64,8 @@ module Mongo
|
|
64
64
|
:text_version => :textIndexVersion,
|
65
65
|
:unique => :unique,
|
66
66
|
:version => :v,
|
67
|
-
:weights => :weights
|
67
|
+
:weights => :weights,
|
68
|
+
:collation => :collation
|
68
69
|
}.freeze
|
69
70
|
|
70
71
|
# Drop an index by its name.
|
@@ -147,11 +148,15 @@ module Mongo
|
|
147
148
|
#
|
148
149
|
# @since 2.0.0
|
149
150
|
def create_many(*models)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
151
|
+
server = next_primary
|
152
|
+
spec = {
|
153
|
+
indexes: normalize_models(models.flatten, server),
|
154
|
+
db_name: database.name,
|
155
|
+
coll_name: collection.name
|
156
|
+
}
|
157
|
+
|
158
|
+
spec[:write_concern] = write_concern if server.features.collation_enabled?
|
159
|
+
Operation::Write::CreateIndex.new(spec).execute(server)
|
155
160
|
end
|
156
161
|
|
157
162
|
# Convenience method for getting index information by a specific name or
|
@@ -213,11 +218,14 @@ module Mongo
|
|
213
218
|
private
|
214
219
|
|
215
220
|
def drop_by_name(name)
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
+
spec = {
|
222
|
+
db_name: database.name,
|
223
|
+
coll_name: collection.name,
|
224
|
+
index_name: name
|
225
|
+
}
|
226
|
+
server = next_primary
|
227
|
+
spec[:write_concern] = write_concern if server.features.collation_enabled?
|
228
|
+
Operation::Write::DropIndex.new(spec).execute(server)
|
221
229
|
end
|
222
230
|
|
223
231
|
def index_name(spec)
|
@@ -243,8 +251,8 @@ module Mongo
|
|
243
251
|
Options::Mapper.transform_keys_to_strings(spec)
|
244
252
|
end
|
245
253
|
|
246
|
-
def normalize_models(models)
|
247
|
-
with_generated_names(models).map do |model|
|
254
|
+
def normalize_models(models, server)
|
255
|
+
with_generated_names(models, server).map do |model|
|
248
256
|
Options::Mapper.transform(model, OPTIONS)
|
249
257
|
end
|
250
258
|
end
|
@@ -253,13 +261,18 @@ module Mongo
|
|
253
261
|
initial_query_op.execute(server)
|
254
262
|
end
|
255
263
|
|
256
|
-
def with_generated_names(models)
|
264
|
+
def with_generated_names(models, server)
|
257
265
|
models.dup.each do |model|
|
266
|
+
validate_collation!(model, server)
|
258
267
|
unless model[:name]
|
259
268
|
model[:name] = index_name(model[:key])
|
260
269
|
end
|
261
270
|
end
|
262
271
|
end
|
272
|
+
|
273
|
+
def validate_collation!(model, server)
|
274
|
+
raise Error::UnsupportedCollation.new if model[:collation] && !server.features.collation_enabled?
|
275
|
+
end
|
263
276
|
end
|
264
277
|
end
|
265
278
|
end
|
data/lib/mongo/operation.rb
CHANGED
@@ -18,6 +18,7 @@ require 'mongo/operation/specifiable'
|
|
18
18
|
require 'mongo/operation/limited'
|
19
19
|
require 'mongo/operation/object_id_generator'
|
20
20
|
require 'mongo/operation/read_preference'
|
21
|
+
require 'mongo/operation/takes_write_concern'
|
21
22
|
require 'mongo/operation/read'
|
22
23
|
require 'mongo/operation/write'
|
23
24
|
require 'mongo/operation/commands'
|
@@ -50,5 +51,10 @@ module Mongo
|
|
50
51
|
#
|
51
52
|
# @since 2.1.0
|
52
53
|
UPSERT = 'upsert'.freeze
|
54
|
+
|
55
|
+
# The collation field constant.
|
56
|
+
#
|
57
|
+
# @since 2.4.0
|
58
|
+
COLLATION = 'collation'.freeze
|
53
59
|
end
|
54
60
|
end
|
@@ -19,6 +19,9 @@ require 'mongo/operation/commands/parallel_scan'
|
|
19
19
|
require 'mongo/operation/commands/aggregate'
|
20
20
|
require 'mongo/operation/commands/map_reduce'
|
21
21
|
require 'mongo/operation/commands/collections_info'
|
22
|
+
require 'mongo/operation/commands/create'
|
23
|
+
require 'mongo/operation/commands/drop'
|
24
|
+
require 'mongo/operation/commands/drop_database'
|
22
25
|
require 'mongo/operation/commands/indexes'
|
23
26
|
require 'mongo/operation/commands/list_collections'
|
24
27
|
require 'mongo/operation/commands/list_indexes'
|
@@ -40,21 +40,21 @@ module Mongo
|
|
40
40
|
#
|
41
41
|
# @since 2.0.0
|
42
42
|
class Aggregate < Command
|
43
|
+
include TakesWriteConcern
|
43
44
|
|
44
45
|
private
|
45
46
|
|
46
|
-
def
|
47
|
-
return
|
48
|
-
|
47
|
+
def filter_cursor_from_selector(sel, server)
|
48
|
+
return sel if server.features.write_command_enabled?
|
49
|
+
sel.reject{ |option, value| option.to_s == 'cursor' }
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
52
|
+
def message(server)
|
53
|
+
sel = update_selector_for_read_pref(selector, server)
|
54
|
+
sel = filter_cursor_from_selector(sel, server)
|
55
|
+
sel = update_selector_for_write_concern(sel, server)
|
56
|
+
opts = update_options_for_slave_ok(options, server)
|
57
|
+
Protocol::Query.new(db_name, query_coll, sel, opts)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
module Commands
|
18
|
+
|
19
|
+
# A MongoDB create collection operation.
|
20
|
+
#
|
21
|
+
# @example Instantiate the operation.
|
22
|
+
# Commands::Create.new(selector: { create: 'test' }, :db_name => 'test')
|
23
|
+
#
|
24
|
+
# Initialization:
|
25
|
+
# param [ Hash ] spec The specifications for the operation.
|
26
|
+
#
|
27
|
+
# option spec :db_name [ String ] The name of the database.
|
28
|
+
# option spec :selector [ Hash ] The create collection selector.
|
29
|
+
# option spec :write_concern [ String ] The write concern to use.
|
30
|
+
# Only applied for server version >= 3.4.
|
31
|
+
#
|
32
|
+
# @since 2.4.0
|
33
|
+
class Create < Command
|
34
|
+
include TakesWriteConcern
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def message(server)
|
39
|
+
sel = update_selector_for_write_concern(selector, server)
|
40
|
+
Protocol::Query.new(db_name, query_coll, sel, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
module Commands
|
18
|
+
|
19
|
+
# A MongoDB drop collection operation.
|
20
|
+
#
|
21
|
+
# @example Instantiate the operation.
|
22
|
+
# Commands::Drop.new(selector: { drop: 'test' }, :db_name => 'test')
|
23
|
+
#
|
24
|
+
# Initialization:
|
25
|
+
# param [ Hash ] spec The specifications for the operation.
|
26
|
+
#
|
27
|
+
# option spec :db_name [ String ] The name of the database.
|
28
|
+
# option spec :selector [ Hash ] The drop collection selector.
|
29
|
+
# option spec :write_concern [ String ] The write concern to use.
|
30
|
+
# Only applied for server version >= 3.4.
|
31
|
+
#
|
32
|
+
# @since 2.4.0
|
33
|
+
class Drop < Command
|
34
|
+
include TakesWriteConcern
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def message(server)
|
39
|
+
sel = update_selector_for_write_concern(selector, server)
|
40
|
+
Protocol::Query.new(db_name, query_coll, sel, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
module Commands
|
18
|
+
|
19
|
+
# A MongoDB drop database operation.
|
20
|
+
#
|
21
|
+
# @example Instantiate the operation.
|
22
|
+
# Commands::Drop.new(selector: { dropDatabase: 'test' }, :db_name => 'test')
|
23
|
+
#
|
24
|
+
# Initialization:
|
25
|
+
# param [ Hash ] spec The specifications for the operation.
|
26
|
+
#
|
27
|
+
# option spec :db_name [ String ] The name of the database.
|
28
|
+
# option spec :selector [ Hash ] The drop database selector.
|
29
|
+
# option spec :write_concern [ String ] The write concern to use.
|
30
|
+
# Only applied for server version >= 3.4.
|
31
|
+
#
|
32
|
+
# @since 2.4.0
|
33
|
+
class DropDatabase < Command
|
34
|
+
include TakesWriteConcern
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def message(server)
|
39
|
+
sel = update_selector_for_write_concern(selector, server)
|
40
|
+
Protocol::Query.new(db_name, query_coll, sel, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|