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.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -1
  3. data/README.md +14 -13
  4. data/lib/config/locales/en.yml +28 -28
  5. data/lib/mongoid.rb +28 -21
  6. data/lib/mongoid/atomic.rb +2 -4
  7. data/lib/mongoid/attributes.rb +7 -7
  8. data/lib/mongoid/attributes/processing.rb +4 -1
  9. data/lib/mongoid/attributes/readonly.rb +2 -2
  10. data/lib/mongoid/changeable.rb +4 -6
  11. data/lib/mongoid/clients.rb +142 -0
  12. data/lib/mongoid/clients/factory.rb +78 -0
  13. data/lib/mongoid/{sessions → clients}/options.rb +30 -19
  14. data/lib/mongoid/{sessions → clients}/storage_options.rb +27 -13
  15. data/lib/mongoid/{sessions → clients}/thread_options.rb +6 -3
  16. data/lib/mongoid/clients/validators.rb +2 -0
  17. data/lib/mongoid/{sessions → clients}/validators/storage.rb +5 -2
  18. data/lib/mongoid/composable.rb +3 -3
  19. data/lib/mongoid/config.rb +39 -41
  20. data/lib/mongoid/config/environment.rb +1 -1
  21. data/lib/mongoid/config/validators.rb +1 -1
  22. data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
  23. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  24. data/lib/mongoid/contextual/atomic.rb +11 -11
  25. data/lib/mongoid/contextual/command.rb +9 -6
  26. data/lib/mongoid/contextual/geo_near.rb +17 -1
  27. data/lib/mongoid/contextual/map_reduce.rb +12 -11
  28. data/lib/mongoid/contextual/memory.rb +2 -5
  29. data/lib/mongoid/contextual/mongo.rb +92 -82
  30. data/lib/mongoid/contextual/none.rb +13 -0
  31. data/lib/mongoid/copyable.rb +6 -1
  32. data/lib/mongoid/criteria.rb +36 -3
  33. data/lib/mongoid/document.rb +3 -4
  34. data/lib/mongoid/errors.rb +6 -6
  35. data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
  36. data/lib/mongoid/errors/no_client_config.rb +22 -0
  37. data/lib/mongoid/errors/{no_session_database.rb → no_client_database.rb} +4 -4
  38. data/lib/mongoid/errors/{no_session_hosts.rb → no_client_hosts.rb} +4 -4
  39. data/lib/mongoid/errors/{no_sessions_config.rb → no_clients_config.rb} +4 -4
  40. data/lib/mongoid/errors/no_default_client.rb +23 -0
  41. data/lib/mongoid/extensions/hash.rb +5 -1
  42. data/lib/mongoid/extensions/object.rb +3 -2
  43. data/lib/mongoid/extensions/set.rb +5 -5
  44. data/lib/mongoid/factory.rb +4 -2
  45. data/lib/mongoid/fields.rb +7 -2
  46. data/lib/mongoid/findable.rb +4 -1
  47. data/lib/mongoid/indexable.rb +15 -9
  48. data/lib/mongoid/persistable.rb +1 -2
  49. data/lib/mongoid/persistable/creatable.rb +2 -2
  50. data/lib/mongoid/persistable/deletable.rb +3 -3
  51. data/lib/mongoid/persistable/incrementable.rb +1 -1
  52. data/lib/mongoid/persistable/logical.rb +1 -1
  53. data/lib/mongoid/persistable/poppable.rb +1 -1
  54. data/lib/mongoid/persistable/pullable.rb +2 -2
  55. data/lib/mongoid/persistable/pushable.rb +2 -2
  56. data/lib/mongoid/persistable/renamable.rb +1 -1
  57. data/lib/mongoid/persistable/settable.rb +1 -1
  58. data/lib/mongoid/persistable/unsettable.rb +1 -1
  59. data/lib/mongoid/persistable/updatable.rb +2 -2
  60. data/lib/mongoid/persistable/upsertable.rb +1 -1
  61. data/lib/mongoid/query_cache.rb +98 -104
  62. data/lib/mongoid/railtie.rb +1 -21
  63. data/lib/mongoid/railties/database.rake +1 -1
  64. data/lib/mongoid/relations/builders.rb +3 -1
  65. data/lib/mongoid/relations/counter_cache.rb +1 -1
  66. data/lib/mongoid/relations/embedded/batchable.rb +3 -10
  67. data/lib/mongoid/relations/embedded/many.rb +4 -2
  68. data/lib/mongoid/relations/many.rb +1 -0
  69. data/lib/mongoid/relations/proxy.rb +6 -6
  70. data/lib/mongoid/relations/referenced/many.rb +2 -1
  71. data/lib/mongoid/relations/targets/enumerable.rb +11 -11
  72. data/lib/mongoid/relations/touchable.rb +1 -1
  73. data/lib/mongoid/reloadable.rb +2 -2
  74. data/lib/mongoid/scopable.rb +6 -17
  75. data/lib/mongoid/selectable.rb +1 -36
  76. data/lib/mongoid/serializable.rb +2 -2
  77. data/lib/mongoid/stateful.rb +0 -1
  78. data/lib/mongoid/tasks/database.rake +2 -2
  79. data/lib/mongoid/tasks/database.rb +23 -16
  80. data/lib/mongoid/threaded.rb +54 -33
  81. data/lib/mongoid/threaded/lifecycle.rb +21 -16
  82. data/lib/mongoid/traversable.rb +16 -1
  83. data/lib/mongoid/validatable.rb +1 -1
  84. data/lib/mongoid/validatable/queryable.rb +1 -1
  85. data/lib/mongoid/validatable/uniqueness.rb +3 -20
  86. data/lib/mongoid/version.rb +1 -1
  87. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +91 -57
  88. data/lib/rails/mongoid.rb +2 -2
  89. data/spec/app/models/audio.rb +1 -1
  90. data/spec/app/models/band.rb +1 -0
  91. data/spec/app/models/company.rb +5 -0
  92. data/spec/app/models/label.rb +7 -0
  93. data/spec/app/models/pub.rb +6 -0
  94. data/spec/app/models/staff.rb +7 -0
  95. data/spec/app/models/store_as_dup_test1.rb +5 -0
  96. data/spec/app/models/store_as_dup_test2.rb +5 -0
  97. data/spec/config/mongoid.yml +7 -25
  98. data/spec/mongoid/atomic/paths_spec.rb +3 -11
  99. data/spec/mongoid/attributes/nested_spec.rb +16 -16
  100. data/spec/mongoid/attributes/readonly_spec.rb +80 -18
  101. data/spec/mongoid/attributes_spec.rb +3 -3
  102. data/spec/mongoid/changeable_spec.rb +70 -0
  103. data/spec/mongoid/clients/factory_spec.rb +284 -0
  104. data/spec/mongoid/{sessions → clients}/options_spec.rb +4 -6
  105. data/spec/mongoid/clients_spec.rb +739 -0
  106. data/spec/mongoid/config/environment_spec.rb +14 -11
  107. data/spec/mongoid/config_spec.rb +33 -48
  108. data/spec/mongoid/contextual/atomic_spec.rb +1 -17
  109. data/spec/mongoid/contextual/geo_near_spec.rb +35 -0
  110. data/spec/mongoid/contextual/mongo_spec.rb +26 -83
  111. data/spec/mongoid/contextual/none_spec.rb +15 -0
  112. data/spec/mongoid/copyable_spec.rb +35 -1
  113. data/spec/mongoid/criteria/findable_spec.rb +197 -0
  114. data/spec/mongoid/criteria/modifiable_spec.rb +7 -29
  115. data/spec/mongoid/criteria_spec.rb +74 -91
  116. data/spec/mongoid/document_spec.rb +1 -1
  117. data/spec/mongoid/errors/{mixed_session_configuration_spec.rb → mixed_client_configuration_spec.rb} +1 -1
  118. data/spec/mongoid/errors/{no_session_config_spec.rb → no_client_config_spec.rb} +4 -4
  119. data/spec/mongoid/errors/{no_session_database_spec.rb → no_client_database_spec.rb} +4 -4
  120. data/spec/mongoid/errors/{no_session_hosts_spec.rb → no_client_hosts_spec.rb} +3 -3
  121. data/spec/mongoid/errors/{no_sessions_config_spec.rb → no_clients_config_spec.rb} +2 -2
  122. data/spec/mongoid/fields/localized_spec.rb +1 -0
  123. data/spec/mongoid/fields_spec.rb +1 -0
  124. data/spec/mongoid/findable_spec.rb +2 -23
  125. data/spec/mongoid/indexable_spec.rb +12 -8
  126. data/spec/mongoid/interceptable_spec.rb +15 -0
  127. data/spec/mongoid/persistable/settable_spec.rb +16 -0
  128. data/spec/mongoid/persistable/updatable_spec.rb +3 -2
  129. data/spec/mongoid/persistable_spec.rb +4 -4
  130. data/spec/mongoid/query_cache_spec.rb +13 -8
  131. data/spec/mongoid/relations/auto_save_spec.rb +1 -1
  132. data/spec/mongoid/relations/counter_cache_spec.rb +34 -0
  133. data/spec/mongoid/relations/eager/belongs_to_spec.rb +9 -0
  134. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +3 -3
  135. data/spec/mongoid/relations/embedded/many_spec.rb +123 -1
  136. data/spec/mongoid/relations/embedded/one_spec.rb +3 -3
  137. data/spec/mongoid/relations/proxy_spec.rb +28 -0
  138. data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
  139. data/spec/mongoid/relations/referenced/many_spec.rb +47 -23
  140. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
  141. data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
  142. data/spec/mongoid/relations/targets/enumerable_spec.rb +9 -2
  143. data/spec/mongoid/reloadable_spec.rb +6 -6
  144. data/spec/mongoid/scopable_spec.rb +41 -28
  145. data/spec/mongoid/selectable_spec.rb +6 -16
  146. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  147. data/spec/mongoid/tasks/database_spec.rb +2 -2
  148. data/spec/mongoid/threaded_spec.rb +0 -7
  149. data/spec/mongoid/traversable_spec.rb +2 -2
  150. data/spec/mongoid/validatable/uniqueness_spec.rb +30 -1
  151. data/spec/mongoid_spec.rb +13 -15
  152. data/spec/rails/mongoid_spec.rb +13 -4
  153. data/spec/spec_helper.rb +44 -27
  154. data/spec/support/authorization.rb +12 -0
  155. data/spec/support/expectations.rb +14 -0
  156. metadata +52 -59
  157. data/lib/mongoid/contextual/find_and_modify.rb +0 -69
  158. data/lib/mongoid/contextual/text_search.rb +0 -178
  159. data/lib/mongoid/criteria/#findable.rb# +0 -141
  160. data/lib/mongoid/errors/no_default_session.rb +0 -23
  161. data/lib/mongoid/errors/no_session_config.rb +0 -22
  162. data/lib/mongoid/log_subscriber.rb +0 -55
  163. data/lib/mongoid/positional.rb +0 -71
  164. data/lib/mongoid/sessions.rb +0 -125
  165. data/lib/mongoid/sessions/factory.rb +0 -131
  166. data/lib/mongoid/sessions/mongo_uri.rb +0 -93
  167. data/lib/mongoid/sessions/validators.rb +0 -2
  168. data/lib/mongoid/support/query_counter.rb +0 -23
  169. data/spec/helpers.rb +0 -18
  170. data/spec/mongoid/#atomic_spec.rb# +0 -365
  171. data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
  172. data/spec/mongoid/contextual/text_search_spec.rb +0 -209
  173. data/spec/mongoid/log_subscriber_spec.rb +0 -75
  174. data/spec/mongoid/positional_spec.rb +0 -222
  175. data/spec/mongoid/sessions/factory_spec.rb +0 -333
  176. data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
  177. data/spec/mongoid/sessions_spec.rb +0 -1252
@@ -1,14 +1,17 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- module Sessions
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 session_name
10
- Threaded.session_override || super
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
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "mongoid/clients/validators/storage"
@@ -1,13 +1,16 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- module Sessions
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
- VALID_OPTIONS = [ :collection, :database, :session ]
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
  #
@@ -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
- Sessions,
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{ |m| m.to_sym }
100
+ mod.instance_methods.map(&:to_sym)
101
101
  end
102
102
  end
103
103
  end
@@ -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
- # session config exists.
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
- sessions.has_key?(:default)
39
+ clients.key?(:default)
39
40
  end
40
41
 
41
- # Connect to the provided database name on the default session.
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.sessions = {
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
- Sessions.disconnect
86
- Sessions.clear
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.sessions = configuration[:sessions]
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 session to use globally.
148
+ # Override the client to use globally.
148
149
  #
149
- # @example Override the session globally.
150
- # config.override_session(:optional)
150
+ # @example Override the client globally.
151
+ # config.override_client(:optional)
151
152
  #
152
- # @param [ String, Symbol ] name The name of the session.
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 override_session(name)
158
- Threaded.session_override = name ? name.to_s : nil
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
- Sessions.default.collections.each do |collection|
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
- Sessions.default.collections.each do |collection|
189
- collection.find.remove_all
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 session configuration or an empty hash.
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 Set the session configuration options.
225
- # config.sessions = { default: { hosts: [ "localhost:27017" ] }}
213
+ # @example Get the clients configuration.
214
+ # config.clients
226
215
  #
227
- # @param [ Hash ] sessions The configuration options.
216
+ # @return [ Hash ] The clients configuration.
228
217
  #
229
218
  # @since 3.0.0
230
- def sessions=(sessions)
231
- raise Errors::NoSessionsConfig.new unless sessions
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
@@ -1,3 +1,3 @@
1
1
  # encoding: utf-8
2
2
  require "mongoid/config/validators/option"
3
- require "mongoid/config/validators/session"
3
+ require "mongoid/config/validators/client"
@@ -3,82 +3,85 @@ module Mongoid
3
3
  module Config
4
4
  module Validators
5
5
 
6
- # Validator for session specific configuration.
7
- module Session
6
+ # Validator for client specific configuration.
7
+ module Client
8
8
  extend self
9
9
 
10
- STANDARD = [ :database, :hosts, :username, :password ]
10
+ # Standard configuration options.
11
+ #
12
+ # @since 3.0.0
13
+ STANDARD = [ :database, :hosts, :username, :password ].freeze
11
14
 
12
- # Validate the session configuration.
15
+ # Validate the client configuration.
13
16
  #
14
- # @example Validate the session config.
15
- # Session.validate({ default: { hosts: [ "localhost:27017" ] }})
17
+ # @example Validate the client config.
18
+ # Client.validate({ default: { hosts: [ "localhost:27017" ] }})
16
19
  #
17
- # @param [ Hash ] sessions The sessions config.
20
+ # @param [ Hash ] clients The clients config.
18
21
  #
19
22
  # @since 3.0.0
20
- def validate(sessions)
21
- unless sessions.has_key?(:default)
22
- raise Errors::NoDefaultSession.new(sessions.keys)
23
+ def validate(clients)
24
+ unless clients.has_key?(:default)
25
+ raise Errors::NoDefaultClient.new(clients.keys)
23
26
  end
24
- sessions.each_pair do |name, config|
25
- validate_session_database(name, config)
26
- validate_session_hosts(name, config)
27
- validate_session_uri(name, config)
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 session config has database.
36
+ # Validate that the client config has database.
34
37
  #
35
38
  # @api private
36
39
  #
37
- # @example Validate the session has database.
38
- # validator.validate_session_database(:default, {})
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 validate_session_database(name, config)
47
+ def validate_client_database(name, config)
45
48
  if no_database_or_uri?(config)
46
- raise Errors::NoSessionDatabase.new(name, config)
49
+ raise Errors::NoClientDatabase.new(name, config)
47
50
  end
48
51
  end
49
52
 
50
- # Validate that the session config has hosts.
53
+ # Validate that the client config has hosts.
51
54
  #
52
55
  # @api private
53
56
  #
54
- # @example Validate the session has hosts.
55
- # validator.validate_session_hosts(:default, {})
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 validate_session_hosts(name, config)
64
+ def validate_client_hosts(name, config)
62
65
  if no_hosts_or_uri?(config)
63
- raise Errors::NoSessionHosts.new(name, config)
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 session.
71
+ # single client.
69
72
  #
70
73
  # @api private
71
74
  #
72
75
  # @example Validate the uri and options.
73
- # validator.validate_session_uri(:default, {})
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 validate_session_uri(name, config)
82
+ def validate_client_uri(name, config)
80
83
  if both_uri_and_standard?(config)
81
- raise Errors::MixedSessionConfiguration.new(name, config)
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
- query.update_all("$addToSet" => collect_operations(adds))
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
- query.update_all("$bit" => collect_operations(bits))
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
- query.update_all("$inc" => collect_operations(incs))
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
- query.update_all("$pop" => collect_operations(pops))
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
- query.update_all("$pull" => collect_operations(pulls))
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
- query.update_all("$pullAll" => collect_operations(pulls))
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
- query.update_all("$push" => collect_operations(pushes))
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
- query.update_all("$pushAll" => collect_operations(pushes))
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
- query.update_all("$rename" => collect_operations(operations))
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
- query.update_all("$set" => collect_operations(sets))
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
- query.update_all("$unset" => Hash[fields])
167
+ view.update_many("$unset" => Hash[fields])
168
168
  end
169
169
 
170
170
  private