mongoid 4.0.2 → 5.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -1
- data/README.md +14 -13
- data/lib/config/locales/en.yml +28 -28
- data/lib/mongoid.rb +28 -21
- data/lib/mongoid/atomic.rb +2 -4
- data/lib/mongoid/attributes.rb +7 -7
- data/lib/mongoid/attributes/processing.rb +4 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/changeable.rb +4 -6
- data/lib/mongoid/clients.rb +142 -0
- data/lib/mongoid/clients/factory.rb +78 -0
- data/lib/mongoid/{sessions → clients}/options.rb +30 -19
- data/lib/mongoid/{sessions → clients}/storage_options.rb +27 -13
- data/lib/mongoid/{sessions → clients}/thread_options.rb +6 -3
- data/lib/mongoid/clients/validators.rb +2 -0
- data/lib/mongoid/{sessions → clients}/validators/storage.rb +5 -2
- data/lib/mongoid/composable.rb +3 -3
- data/lib/mongoid/config.rb +39 -41
- data/lib/mongoid/config/environment.rb +1 -1
- data/lib/mongoid/config/validators.rb +1 -1
- data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +11 -11
- data/lib/mongoid/contextual/command.rb +9 -6
- data/lib/mongoid/contextual/geo_near.rb +17 -1
- data/lib/mongoid/contextual/map_reduce.rb +12 -11
- data/lib/mongoid/contextual/memory.rb +2 -5
- data/lib/mongoid/contextual/mongo.rb +92 -82
- data/lib/mongoid/contextual/none.rb +13 -0
- data/lib/mongoid/copyable.rb +6 -1
- data/lib/mongoid/criteria.rb +36 -3
- data/lib/mongoid/document.rb +3 -4
- data/lib/mongoid/errors.rb +6 -6
- data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
- data/lib/mongoid/errors/no_client_config.rb +22 -0
- data/lib/mongoid/errors/{no_session_database.rb → no_client_database.rb} +4 -4
- data/lib/mongoid/errors/{no_session_hosts.rb → no_client_hosts.rb} +4 -4
- data/lib/mongoid/errors/{no_sessions_config.rb → no_clients_config.rb} +4 -4
- data/lib/mongoid/errors/no_default_client.rb +23 -0
- data/lib/mongoid/extensions/hash.rb +5 -1
- data/lib/mongoid/extensions/object.rb +3 -2
- data/lib/mongoid/extensions/set.rb +5 -5
- data/lib/mongoid/factory.rb +4 -2
- data/lib/mongoid/fields.rb +7 -2
- data/lib/mongoid/findable.rb +4 -1
- data/lib/mongoid/indexable.rb +15 -9
- data/lib/mongoid/persistable.rb +1 -2
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +3 -3
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/poppable.rb +1 -1
- data/lib/mongoid/persistable/pullable.rb +2 -2
- data/lib/mongoid/persistable/pushable.rb +2 -2
- data/lib/mongoid/persistable/renamable.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +1 -1
- data/lib/mongoid/persistable/unsettable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/query_cache.rb +98 -104
- data/lib/mongoid/railtie.rb +1 -21
- data/lib/mongoid/railties/database.rake +1 -1
- data/lib/mongoid/relations/builders.rb +3 -1
- data/lib/mongoid/relations/counter_cache.rb +1 -1
- data/lib/mongoid/relations/embedded/batchable.rb +3 -10
- data/lib/mongoid/relations/embedded/many.rb +4 -2
- data/lib/mongoid/relations/many.rb +1 -0
- data/lib/mongoid/relations/proxy.rb +6 -6
- data/lib/mongoid/relations/referenced/many.rb +2 -1
- data/lib/mongoid/relations/targets/enumerable.rb +11 -11
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +2 -2
- data/lib/mongoid/scopable.rb +6 -17
- data/lib/mongoid/selectable.rb +1 -36
- data/lib/mongoid/serializable.rb +2 -2
- data/lib/mongoid/stateful.rb +0 -1
- data/lib/mongoid/tasks/database.rake +2 -2
- data/lib/mongoid/tasks/database.rb +23 -16
- data/lib/mongoid/threaded.rb +54 -33
- data/lib/mongoid/threaded/lifecycle.rb +21 -16
- data/lib/mongoid/traversable.rb +16 -1
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/validatable/queryable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +3 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +91 -57
- data/lib/rails/mongoid.rb +2 -2
- data/spec/app/models/audio.rb +1 -1
- data/spec/app/models/band.rb +1 -0
- data/spec/app/models/company.rb +5 -0
- data/spec/app/models/label.rb +7 -0
- data/spec/app/models/pub.rb +6 -0
- data/spec/app/models/staff.rb +7 -0
- data/spec/app/models/store_as_dup_test1.rb +5 -0
- data/spec/app/models/store_as_dup_test2.rb +5 -0
- data/spec/config/mongoid.yml +7 -25
- data/spec/mongoid/atomic/paths_spec.rb +3 -11
- data/spec/mongoid/attributes/nested_spec.rb +16 -16
- data/spec/mongoid/attributes/readonly_spec.rb +80 -18
- data/spec/mongoid/attributes_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +70 -0
- data/spec/mongoid/clients/factory_spec.rb +284 -0
- data/spec/mongoid/{sessions → clients}/options_spec.rb +4 -6
- data/spec/mongoid/clients_spec.rb +739 -0
- data/spec/mongoid/config/environment_spec.rb +14 -11
- data/spec/mongoid/config_spec.rb +33 -48
- data/spec/mongoid/contextual/atomic_spec.rb +1 -17
- data/spec/mongoid/contextual/geo_near_spec.rb +35 -0
- data/spec/mongoid/contextual/mongo_spec.rb +26 -83
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +35 -1
- data/spec/mongoid/criteria/findable_spec.rb +197 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +7 -29
- data/spec/mongoid/criteria_spec.rb +74 -91
- data/spec/mongoid/document_spec.rb +1 -1
- data/spec/mongoid/errors/{mixed_session_configuration_spec.rb → mixed_client_configuration_spec.rb} +1 -1
- data/spec/mongoid/errors/{no_session_config_spec.rb → no_client_config_spec.rb} +4 -4
- data/spec/mongoid/errors/{no_session_database_spec.rb → no_client_database_spec.rb} +4 -4
- data/spec/mongoid/errors/{no_session_hosts_spec.rb → no_client_hosts_spec.rb} +3 -3
- data/spec/mongoid/errors/{no_sessions_config_spec.rb → no_clients_config_spec.rb} +2 -2
- data/spec/mongoid/fields/localized_spec.rb +1 -0
- data/spec/mongoid/fields_spec.rb +1 -0
- data/spec/mongoid/findable_spec.rb +2 -23
- data/spec/mongoid/indexable_spec.rb +12 -8
- data/spec/mongoid/interceptable_spec.rb +15 -0
- data/spec/mongoid/persistable/settable_spec.rb +16 -0
- data/spec/mongoid/persistable/updatable_spec.rb +3 -2
- data/spec/mongoid/persistable_spec.rb +4 -4
- data/spec/mongoid/query_cache_spec.rb +13 -8
- data/spec/mongoid/relations/auto_save_spec.rb +1 -1
- data/spec/mongoid/relations/counter_cache_spec.rb +34 -0
- data/spec/mongoid/relations/eager/belongs_to_spec.rb +9 -0
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +3 -3
- data/spec/mongoid/relations/embedded/many_spec.rb +123 -1
- data/spec/mongoid/relations/embedded/one_spec.rb +3 -3
- data/spec/mongoid/relations/proxy_spec.rb +28 -0
- data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +47 -23
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
- data/spec/mongoid/relations/targets/enumerable_spec.rb +9 -2
- data/spec/mongoid/reloadable_spec.rb +6 -6
- data/spec/mongoid/scopable_spec.rb +41 -28
- data/spec/mongoid/selectable_spec.rb +6 -16
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +2 -2
- data/spec/mongoid/threaded_spec.rb +0 -7
- data/spec/mongoid/traversable_spec.rb +2 -2
- data/spec/mongoid/validatable/uniqueness_spec.rb +30 -1
- data/spec/mongoid_spec.rb +13 -15
- data/spec/rails/mongoid_spec.rb +13 -4
- data/spec/spec_helper.rb +44 -27
- data/spec/support/authorization.rb +12 -0
- data/spec/support/expectations.rb +14 -0
- metadata +52 -59
- data/lib/mongoid/contextual/find_and_modify.rb +0 -69
- data/lib/mongoid/contextual/text_search.rb +0 -178
- data/lib/mongoid/criteria/#findable.rb# +0 -141
- data/lib/mongoid/errors/no_default_session.rb +0 -23
- data/lib/mongoid/errors/no_session_config.rb +0 -22
- data/lib/mongoid/log_subscriber.rb +0 -55
- data/lib/mongoid/positional.rb +0 -71
- data/lib/mongoid/sessions.rb +0 -125
- data/lib/mongoid/sessions/factory.rb +0 -131
- data/lib/mongoid/sessions/mongo_uri.rb +0 -93
- data/lib/mongoid/sessions/validators.rb +0 -2
- data/lib/mongoid/support/query_counter.rb +0 -23
- data/spec/helpers.rb +0 -18
- data/spec/mongoid/#atomic_spec.rb# +0 -365
- data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
- data/spec/mongoid/contextual/text_search_spec.rb +0 -209
- data/spec/mongoid/log_subscriber_spec.rb +0 -75
- data/spec/mongoid/positional_spec.rb +0 -222
- data/spec/mongoid/sessions/factory_spec.rb +0 -333
- data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
- data/spec/mongoid/sessions_spec.rb +0 -1252
@@ -1,14 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid
|
3
|
-
module
|
3
|
+
module Clients
|
4
4
|
module ThreadOptions
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
+
extend Gem::Deprecate
|
8
9
|
|
9
|
-
def
|
10
|
-
Threaded.
|
10
|
+
def client_name
|
11
|
+
Threaded.client_override || super
|
11
12
|
end
|
13
|
+
alias :session_name :client_name
|
14
|
+
deprecate :session_name, :client_name, 2015, 12
|
12
15
|
|
13
16
|
def database_name
|
14
17
|
Threaded.database_override || super
|
@@ -1,13 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid
|
3
|
-
module
|
3
|
+
module Clients
|
4
4
|
module Validators
|
5
5
|
|
6
6
|
# Validates the options passed to :store_in.
|
7
7
|
module Storage
|
8
8
|
extend self
|
9
9
|
|
10
|
-
|
10
|
+
# The valid options for storage.
|
11
|
+
#
|
12
|
+
# @since 3.0.0
|
13
|
+
VALID_OPTIONS = [ :collection, :database, :client ].freeze
|
11
14
|
|
12
15
|
# Validate the options provided to :store_in.
|
13
16
|
#
|
data/lib/mongoid/composable.rb
CHANGED
@@ -35,6 +35,7 @@ module Mongoid
|
|
35
35
|
include ActiveModel::Serializers::Xml
|
36
36
|
include Atomic
|
37
37
|
include Changeable
|
38
|
+
include Clients
|
38
39
|
include Attributes
|
39
40
|
include Evolvable
|
40
41
|
include Fields
|
@@ -47,7 +48,6 @@ module Mongoid
|
|
47
48
|
include Scopable
|
48
49
|
include Selectable
|
49
50
|
include Serializable
|
50
|
-
include Sessions
|
51
51
|
include Shardable
|
52
52
|
include Stateful
|
53
53
|
include Threaded::Lifecycle
|
@@ -73,7 +73,7 @@ module Mongoid
|
|
73
73
|
Reloadable,
|
74
74
|
Scopable,
|
75
75
|
Serializable,
|
76
|
-
|
76
|
+
Clients,
|
77
77
|
Shardable,
|
78
78
|
Stateful,
|
79
79
|
Threaded::Lifecycle,
|
@@ -97,7 +97,7 @@ module Mongoid
|
|
97
97
|
# @since 2.1.8
|
98
98
|
def prohibited_methods
|
99
99
|
@prohibited_methods ||= MODULES.flat_map do |mod|
|
100
|
-
mod.instance_methods.map
|
100
|
+
mod.instance_methods.map(&:to_sym)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
data/lib/mongoid/config.rb
CHANGED
@@ -8,6 +8,7 @@ module Mongoid
|
|
8
8
|
# This module defines all the configuration options for Mongoid, including the
|
9
9
|
# database connections.
|
10
10
|
module Config
|
11
|
+
extend Gem::Deprecate
|
11
12
|
extend self
|
12
13
|
extend Options
|
13
14
|
|
@@ -26,7 +27,7 @@ module Mongoid
|
|
26
27
|
option :use_utc, default: false
|
27
28
|
|
28
29
|
# Has Mongoid been configured? This is checking that at least a valid
|
29
|
-
#
|
30
|
+
# client config exists.
|
30
31
|
#
|
31
32
|
# @example Is Mongoid configured?
|
32
33
|
# config.configured?
|
@@ -35,10 +36,10 @@ module Mongoid
|
|
35
36
|
#
|
36
37
|
# @since 3.0.9
|
37
38
|
def configured?
|
38
|
-
|
39
|
+
clients.key?(:default)
|
39
40
|
end
|
40
41
|
|
41
|
-
# Connect to the provided database name on the default
|
42
|
+
# Connect to the provided database name on the default client.
|
42
43
|
#
|
43
44
|
# @note Use only in development or test environments for convenience.
|
44
45
|
#
|
@@ -48,8 +49,8 @@ module Mongoid
|
|
48
49
|
# @param [ String ] name The database name.
|
49
50
|
#
|
50
51
|
# @since 3.0.0
|
51
|
-
def connect_to(name, options = { read: :primary })
|
52
|
-
self.
|
52
|
+
def connect_to(name, options = { read: { mode: :primary }})
|
53
|
+
self.clients = {
|
53
54
|
default: {
|
54
55
|
database: name,
|
55
56
|
hosts: [ "localhost:27017" ],
|
@@ -82,8 +83,8 @@ module Mongoid
|
|
82
83
|
def load!(path, environment = nil)
|
83
84
|
settings = Environment.load_yaml(path, environment)
|
84
85
|
if settings.present?
|
85
|
-
|
86
|
-
|
86
|
+
Clients.disconnect
|
87
|
+
Clients.clear
|
87
88
|
load_configuration(settings)
|
88
89
|
end
|
89
90
|
settings
|
@@ -127,7 +128,7 @@ module Mongoid
|
|
127
128
|
def load_configuration(settings)
|
128
129
|
configuration = settings.with_indifferent_access
|
129
130
|
self.options = configuration[:options]
|
130
|
-
self.
|
131
|
+
self.clients = configuration[:clients]
|
131
132
|
end
|
132
133
|
|
133
134
|
# Override the database to use globally.
|
@@ -144,19 +145,21 @@ module Mongoid
|
|
144
145
|
Threaded.database_override = name
|
145
146
|
end
|
146
147
|
|
147
|
-
# Override the
|
148
|
+
# Override the client to use globally.
|
148
149
|
#
|
149
|
-
# @example Override the
|
150
|
-
# config.
|
150
|
+
# @example Override the client globally.
|
151
|
+
# config.override_client(:optional)
|
151
152
|
#
|
152
|
-
# @param [ String, Symbol ] name The name of the
|
153
|
+
# @param [ String, Symbol ] name The name of the client.
|
153
154
|
#
|
154
155
|
# @return [ String, Symbol ] The global override.
|
155
156
|
#
|
156
157
|
# @since 3.0.0
|
157
|
-
def
|
158
|
-
Threaded.
|
158
|
+
def override_client(name)
|
159
|
+
Threaded.client_override = name ? name.to_s : nil
|
159
160
|
end
|
161
|
+
alias :override_session :override_client
|
162
|
+
deprecate :override_session, :override_client, 2015, 12
|
160
163
|
|
161
164
|
# Purge all data in all collections, including indexes.
|
162
165
|
#
|
@@ -169,9 +172,7 @@ module Mongoid
|
|
169
172
|
#
|
170
173
|
# @since 2.0.2
|
171
174
|
def purge!
|
172
|
-
|
173
|
-
collection.drop
|
174
|
-
end and true
|
175
|
+
Clients.default.database.collections.each(&:drop) and true
|
175
176
|
end
|
176
177
|
|
177
178
|
# Truncate all data in all collections, but not the indexes.
|
@@ -185,8 +186,8 @@ module Mongoid
|
|
185
186
|
#
|
186
187
|
# @since 2.0.2
|
187
188
|
def truncate!
|
188
|
-
|
189
|
-
collection.find.
|
189
|
+
Clients.default.database.collections.each do |collection|
|
190
|
+
collection.find.delete_many
|
190
191
|
end and true
|
191
192
|
end
|
192
193
|
|
@@ -207,33 +208,19 @@ module Mongoid
|
|
207
208
|
end
|
208
209
|
end
|
209
210
|
|
210
|
-
# Get the
|
211
|
-
#
|
212
|
-
# @example Get the sessions configuration.
|
213
|
-
# config.sessions
|
214
|
-
#
|
215
|
-
# @return [ Hash ] The sessions configuration.
|
216
|
-
#
|
217
|
-
# @since 3.0.0
|
218
|
-
def sessions
|
219
|
-
@sessions ||= {}
|
220
|
-
end
|
221
|
-
|
222
|
-
# Set the session configuration options.
|
211
|
+
# Get the client configuration or an empty hash.
|
223
212
|
#
|
224
|
-
# @example
|
225
|
-
# config.
|
213
|
+
# @example Get the clients configuration.
|
214
|
+
# config.clients
|
226
215
|
#
|
227
|
-
# @
|
216
|
+
# @return [ Hash ] The clients configuration.
|
228
217
|
#
|
229
218
|
# @since 3.0.0
|
230
|
-
def
|
231
|
-
|
232
|
-
sess = sessions.with_indifferent_access
|
233
|
-
Validators::Session.validate(sess)
|
234
|
-
@sessions = sess
|
235
|
-
sess
|
219
|
+
def clients
|
220
|
+
@clients ||= {}
|
236
221
|
end
|
222
|
+
alias :sessions :clients
|
223
|
+
deprecate :sessions, :clients, 2015, 12
|
237
224
|
|
238
225
|
# Get the time zone to use.
|
239
226
|
#
|
@@ -258,5 +245,16 @@ module Mongoid
|
|
258
245
|
def running_with_passenger?
|
259
246
|
@running_with_passenger ||= defined?(PhusionPassenger)
|
260
247
|
end
|
248
|
+
|
249
|
+
private
|
250
|
+
|
251
|
+
def clients=(clients)
|
252
|
+
raise Errors::NoClientsConfig.new unless clients
|
253
|
+
c = clients.with_indifferent_access
|
254
|
+
Validators::Client.validate(c)
|
255
|
+
@clients = c
|
256
|
+
end
|
257
|
+
alias :sessions= :clients=
|
258
|
+
deprecate :sessions=, :clients=, 2015, 12
|
261
259
|
end
|
262
260
|
end
|
@@ -19,7 +19,7 @@ module Mongoid
|
|
19
19
|
#
|
20
20
|
# @since 2.3.0
|
21
21
|
def env_name
|
22
|
-
return Rails.env if defined?(Rails)
|
22
|
+
return Rails.env if defined?(Rails) && Rails.respond_to?(:env)
|
23
23
|
return Sinatra::Base.environment.to_s if defined?(Sinatra)
|
24
24
|
ENV["RACK_ENV"] || ENV["MONGOID_ENV"] || raise(Errors::NoEnvironment.new)
|
25
25
|
end
|
@@ -3,82 +3,85 @@ module Mongoid
|
|
3
3
|
module Config
|
4
4
|
module Validators
|
5
5
|
|
6
|
-
# Validator for
|
7
|
-
module
|
6
|
+
# Validator for client specific configuration.
|
7
|
+
module Client
|
8
8
|
extend self
|
9
9
|
|
10
|
-
|
10
|
+
# Standard configuration options.
|
11
|
+
#
|
12
|
+
# @since 3.0.0
|
13
|
+
STANDARD = [ :database, :hosts, :username, :password ].freeze
|
11
14
|
|
12
|
-
# Validate the
|
15
|
+
# Validate the client configuration.
|
13
16
|
#
|
14
|
-
# @example Validate the
|
15
|
-
#
|
17
|
+
# @example Validate the client config.
|
18
|
+
# Client.validate({ default: { hosts: [ "localhost:27017" ] }})
|
16
19
|
#
|
17
|
-
# @param [ Hash ]
|
20
|
+
# @param [ Hash ] clients The clients config.
|
18
21
|
#
|
19
22
|
# @since 3.0.0
|
20
|
-
def validate(
|
21
|
-
unless
|
22
|
-
raise Errors::
|
23
|
+
def validate(clients)
|
24
|
+
unless clients.has_key?(:default)
|
25
|
+
raise Errors::NoDefaultClient.new(clients.keys)
|
23
26
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
clients.each_pair do |name, config|
|
28
|
+
validate_client_database(name, config)
|
29
|
+
validate_client_hosts(name, config)
|
30
|
+
validate_client_uri(name, config)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
34
|
private
|
32
35
|
|
33
|
-
# Validate that the
|
36
|
+
# Validate that the client config has database.
|
34
37
|
#
|
35
38
|
# @api private
|
36
39
|
#
|
37
|
-
# @example Validate the
|
38
|
-
# validator.
|
40
|
+
# @example Validate the client has database.
|
41
|
+
# validator.validate_client_database(:default, {})
|
39
42
|
#
|
40
43
|
# @param [ String, Symbol ] name The config key.
|
41
44
|
# @param [ Hash ] config The configuration.
|
42
45
|
#
|
43
46
|
# @since 3.0.0
|
44
|
-
def
|
47
|
+
def validate_client_database(name, config)
|
45
48
|
if no_database_or_uri?(config)
|
46
|
-
raise Errors::
|
49
|
+
raise Errors::NoClientDatabase.new(name, config)
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
|
-
# Validate that the
|
53
|
+
# Validate that the client config has hosts.
|
51
54
|
#
|
52
55
|
# @api private
|
53
56
|
#
|
54
|
-
# @example Validate the
|
55
|
-
# validator.
|
57
|
+
# @example Validate the client has hosts.
|
58
|
+
# validator.validate_client_hosts(:default, {})
|
56
59
|
#
|
57
60
|
# @param [ String, Symbol ] name The config key.
|
58
61
|
# @param [ Hash ] config The configuration.
|
59
62
|
#
|
60
63
|
# @since 3.0.0
|
61
|
-
def
|
64
|
+
def validate_client_hosts(name, config)
|
62
65
|
if no_hosts_or_uri?(config)
|
63
|
-
raise Errors::
|
66
|
+
raise Errors::NoClientHosts.new(name, config)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
67
70
|
# Validate that not both a uri and standard options are provided for a
|
68
|
-
# single
|
71
|
+
# single client.
|
69
72
|
#
|
70
73
|
# @api private
|
71
74
|
#
|
72
75
|
# @example Validate the uri and options.
|
73
|
-
# validator.
|
76
|
+
# validator.validate_client_uri(:default, {})
|
74
77
|
#
|
75
78
|
# @param [ String, Symbol ] name The config key.
|
76
79
|
# @param [ Hash ] config The configuration.
|
77
80
|
#
|
78
81
|
# @since 3.0.0
|
79
|
-
def
|
82
|
+
def validate_client_uri(name, config)
|
80
83
|
if both_uri_and_standard?(config)
|
81
|
-
raise Errors::
|
84
|
+
raise Errors::MixedClientConfiguration.new(name, config)
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
@@ -23,7 +23,7 @@ module Mongoid
|
|
23
23
|
#
|
24
24
|
# @since 3.0.0
|
25
25
|
def aggregates(field)
|
26
|
-
result = collection.aggregate(pipeline(field)).to_a
|
26
|
+
result = collection.find.aggregate(pipeline(field)).to_a
|
27
27
|
if result.empty?
|
28
28
|
{ "count" => 0, "sum" => nil, "avg" => nil, "min" => nil, "max" => nil }
|
29
29
|
else
|
@@ -14,7 +14,7 @@ module Mongoid
|
|
14
14
|
#
|
15
15
|
# @since 3.0.0
|
16
16
|
def add_to_set(adds)
|
17
|
-
|
17
|
+
view.update_many("$addToSet" => collect_operations(adds))
|
18
18
|
end
|
19
19
|
|
20
20
|
# Perform an atomic $bit operation on the matching documents.
|
@@ -28,7 +28,7 @@ module Mongoid
|
|
28
28
|
#
|
29
29
|
# @since 3.0.0
|
30
30
|
def bit(bits)
|
31
|
-
|
31
|
+
view.update_many("$bit" => collect_operations(bits))
|
32
32
|
end
|
33
33
|
|
34
34
|
# Perform an atomic $inc operation on the matching documents.
|
@@ -42,7 +42,7 @@ module Mongoid
|
|
42
42
|
#
|
43
43
|
# @since 3.0.0
|
44
44
|
def inc(incs)
|
45
|
-
|
45
|
+
view.update_many("$inc" => collect_operations(incs))
|
46
46
|
end
|
47
47
|
|
48
48
|
# Perform an atomic $pop operation on the matching documents.
|
@@ -59,7 +59,7 @@ module Mongoid
|
|
59
59
|
#
|
60
60
|
# @since 3.0.0
|
61
61
|
def pop(pops)
|
62
|
-
|
62
|
+
view.update_many("$pop" => collect_operations(pops))
|
63
63
|
end
|
64
64
|
|
65
65
|
# Perform an atomic $pull operation on the matching documents.
|
@@ -75,7 +75,7 @@ module Mongoid
|
|
75
75
|
#
|
76
76
|
# @since 3.0.0
|
77
77
|
def pull(pulls)
|
78
|
-
|
78
|
+
view.update_many("$pull" => collect_operations(pulls))
|
79
79
|
end
|
80
80
|
|
81
81
|
# Perform an atomic $pullAll operation on the matching documents.
|
@@ -89,7 +89,7 @@ module Mongoid
|
|
89
89
|
#
|
90
90
|
# @since 3.0.0
|
91
91
|
def pull_all(pulls)
|
92
|
-
|
92
|
+
view.update_many("$pullAll" => collect_operations(pulls))
|
93
93
|
end
|
94
94
|
|
95
95
|
# Perform an atomic $push operation on the matching documents.
|
@@ -103,7 +103,7 @@ module Mongoid
|
|
103
103
|
#
|
104
104
|
# @since 3.0.0
|
105
105
|
def push(pushes)
|
106
|
-
|
106
|
+
view.update_many("$push" => collect_operations(pushes))
|
107
107
|
end
|
108
108
|
|
109
109
|
# Perform an atomic $pushAll operation on the matching documents.
|
@@ -117,7 +117,7 @@ module Mongoid
|
|
117
117
|
#
|
118
118
|
# @since 3.0.0
|
119
119
|
def push_all(pushes)
|
120
|
-
|
120
|
+
view.update_many("$pushAll" => collect_operations(pushes))
|
121
121
|
end
|
122
122
|
|
123
123
|
# Perform an atomic $rename of fields on the matching documents.
|
@@ -135,7 +135,7 @@ module Mongoid
|
|
135
135
|
ops[old_name] = new_name.to_s
|
136
136
|
ops
|
137
137
|
end
|
138
|
-
|
138
|
+
view.update_many("$rename" => collect_operations(operations))
|
139
139
|
end
|
140
140
|
|
141
141
|
# Perform an atomic $set of fields on the matching documents.
|
@@ -149,7 +149,7 @@ module Mongoid
|
|
149
149
|
#
|
150
150
|
# @since 3.0.0
|
151
151
|
def set(sets)
|
152
|
-
|
152
|
+
view.update_many("$set" => collect_operations(sets))
|
153
153
|
end
|
154
154
|
|
155
155
|
# Perform an atomic $unset of a field on the matching documents.
|
@@ -164,7 +164,7 @@ module Mongoid
|
|
164
164
|
# @since 3.0.0
|
165
165
|
def unset(*args)
|
166
166
|
fields = args.__find_args__.collect { |f| [database_field_name(f), true] }
|
167
|
-
|
167
|
+
view.update_many("$unset" => Hash[fields])
|
168
168
|
end
|
169
169
|
|
170
170
|
private
|