mongoid 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -1
- data/README.md +11 -19
- data/lib/config/locales/en.yml +33 -30
- data/lib/mongoid/atomic.rb +2 -4
- data/lib/mongoid/attributes/processing.rb +4 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/attributes.rb +7 -7
- data/lib/mongoid/changeable.rb +4 -6
- 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/{sessions → clients}/validators/storage.rb +5 -2
- data/lib/mongoid/clients/validators.rb +2 -0
- data/lib/mongoid/clients.rb +141 -0
- data/lib/mongoid/composable.rb +3 -3
- data/lib/mongoid/config/environment.rb +1 -1
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
- data/lib/mongoid/config/validators/option.rb +1 -1
- data/lib/mongoid/config/validators.rb +1 -1
- data/lib/mongoid/config.rb +39 -41
- 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 +37 -4
- data/lib/mongoid/document.rb +3 -4
- data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
- data/lib/mongoid/errors/mongoid_error.rb +15 -9
- 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/errors.rb +6 -6
- 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/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/persistable.rb +1 -2
- data/lib/mongoid/query_cache.rb +98 -104
- data/lib/mongoid/railtie.rb +4 -25
- data/lib/mongoid/railties/database.rake +1 -1
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -2
- 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/embedded/one.rb +1 -0
- data/lib/mongoid/relations/many.rb +1 -0
- data/lib/mongoid/relations/metadata.rb +14 -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 +24 -17
- data/lib/mongoid/threaded/lifecycle.rb +21 -16
- data/lib/mongoid/threaded.rb +54 -33
- data/lib/mongoid/traversable.rb +17 -1
- data/lib/mongoid/validatable/queryable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +3 -20
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +28 -21
- 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/code.rb +6 -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 +156 -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 +754 -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/mongoid_error_spec.rb +19 -3
- 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 +50 -57
- 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/factory.rb +0 -131
- data/lib/mongoid/sessions/mongo_uri.rb +0 -93
- data/lib/mongoid/sessions/validators.rb +0 -2
- data/lib/mongoid/sessions.rb +0 -125
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: add22f9a2555b543be72f205bad6bc0baa3f00c5
|
|
4
|
+
data.tar.gz: e5e3472e31f1f826a4ad7cd0e2607aeef72a4adc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6349535d149183db9330fa3469e8ad25a119e3bb78545046f0cf44e1de7c75be8ca3f1785aeb387856d2ab7d50e079a17dc3328c3a8fe4d26cf1332923a3a994
|
|
7
|
+
data.tar.gz: 78fecf90c0308eb831ace2022c9acd4ac817b3b4080332a8207c31db0aeafd1d683b4ce30257e99bfe20e1745215d9789d6c88e5a99c05e847d76f77e5f429f9
|
data/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,72 @@
|
|
|
3
3
|
For instructions on upgrading to newer versions, visit
|
|
4
4
|
[mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## 5.0.0 - Not released
|
|
7
|
+
|
|
8
|
+
### Major Changes (Backwards Incompatible)
|
|
9
|
+
|
|
10
|
+
* Mongoid now uses the official Mongo Ruby Driver 2.x instead of Moped.
|
|
11
|
+
|
|
12
|
+
* Most driver specific configuration options have changed, please see [here](http://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial/#ruby-options) for the new options.
|
|
13
|
+
|
|
14
|
+
* All references to `session` are now replaced with `client`. This includes the mongoid.yml configuration, `store_in` options, and all exceptions and modules with `Session` in the name.
|
|
15
|
+
|
|
16
|
+
* `find_and_modify` has been removed and replaced with 3 options: `find_one_and_update`, `find_one_and_delete` and `find_one_and_replace`.
|
|
17
|
+
|
|
18
|
+
* `text_search` has been removed as it is now a `$text` option in a query from 2.6 on.
|
|
19
|
+
|
|
20
|
+
* Mongoid no longer supports MongoDB 2.2 - support is now for only 2.4 and higher.
|
|
21
|
+
|
|
22
|
+
* \#3768 `first` and `last` no longer add an `_id` sort when no sorting options have been provided. In order to guarantee that a document is the first or last, it needs to now contain an explicit sort.
|
|
23
|
+
|
|
24
|
+
* `Document#deleted?` alias has been removed, please continue to use `Document#destroyed?`.
|
|
25
|
+
|
|
26
|
+
### New Features
|
|
27
|
+
|
|
28
|
+
* \#4016 Allow private and protected setters on fields for atomic operations. (Rob Smith)
|
|
29
|
+
|
|
30
|
+
* \#3985 Return nil when using `{upsert: true}` in `find_and_modify` (Adrien Siami)
|
|
31
|
+
|
|
32
|
+
* \#3963 Allow extended JSON object ids to be passed to `find`.
|
|
33
|
+
|
|
34
|
+
* \#3846 Allow #pluck when none is used in criteria. (Braulio Martinez)
|
|
35
|
+
|
|
36
|
+
### Resolved Issues
|
|
37
|
+
|
|
38
|
+
* \#4091 Use sublcass context when calling a scope defined in a superclass. (Edgars Beigarts)
|
|
39
|
+
|
|
40
|
+
* \#4075 Made remove index logging specific to each index that was actually getting removed.
|
|
41
|
+
|
|
42
|
+
* \#4071 Fixed loading of enumerable relation to check the added documents when iterating.
|
|
43
|
+
|
|
44
|
+
* \#4077 Many relations now include Enumerable.
|
|
45
|
+
|
|
46
|
+
* \#4052 Fixed uniqueness validation on localized fields with no value.
|
|
47
|
+
|
|
48
|
+
* \#4033 Removed all uses of the $ positional operator in atomic updates.
|
|
49
|
+
|
|
50
|
+
* \#4030 Dup/clone exceptions auto-include dynamic attributes.
|
|
51
|
+
|
|
52
|
+
* \#4005 Fixed inclusion of mongoid with Rails components that don't have the Rails environment.
|
|
53
|
+
|
|
54
|
+
* \#3993 Fixes issue where `dup`/`clone` fails for embedded documents that use store_as without using Mongoid::Atributes::Dynamic
|
|
55
|
+
|
|
56
|
+
* \#3991 Fixed emebdded documents not flagging as changed after calling #changed? and modifying the
|
|
57
|
+
child elements.
|
|
58
|
+
|
|
59
|
+
* \#3874 Adding snapshot option to context.
|
|
60
|
+
|
|
61
|
+
* \#3868 Loading models in rake tasks now expands the rails path.
|
|
62
|
+
|
|
63
|
+
* \#3764 Fixed case statement check for enumerable targets.
|
|
64
|
+
|
|
65
|
+
* \#3740 Fixes `Missing attribute: '_id'` error when using methods only or without (dx7)
|
|
66
|
+
|
|
67
|
+
* \#3631 Fixes issue where `before_save` callback can get called twice after a child create
|
|
68
|
+
|
|
69
|
+
* \#3599 Fixed application of default scopes from superclass in subclasses.
|
|
70
|
+
|
|
71
|
+
* \#3104 Fixed enumerable targets to check first/last in proper order.
|
|
7
72
|
|
|
8
73
|
## 4.0.2
|
|
9
74
|
|
data/README.md
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# Mongoid
|
|
2
|
-
[](https://travis-ci.org/mongodb/mongoid)
|
|
3
|
+
[](https://codeclimate.com/github/mongodb/mongoid)
|
|
4
|
+
[](https://coveralls.io/r/mongodb/mongoid?branch=master)
|
|
5
5
|
[](https://www.versioneye.com/ruby/mongoid/4.0.0)
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
|
|
9
8
|
|
|
9
|
+
Issues
|
|
10
|
+
------
|
|
11
|
+
|
|
12
|
+
Issues are now in the [Mongoid Jira project](https://jira.mongodb.org/browse/MONGOID/).
|
|
13
|
+
|
|
10
14
|
Project Tracking
|
|
11
15
|
----------------
|
|
12
16
|
|
|
@@ -18,29 +22,17 @@ Project Tracking
|
|
|
18
22
|
Compatibility
|
|
19
23
|
-------------
|
|
20
24
|
|
|
21
|
-
Mongoid is tested against MRI 1.9.3, 2.0.0, 2.1.0 and JRuby (1.9).
|
|
25
|
+
Mongoid is tested against MRI 1.9.3, 2.0.0, 2.1.0. 2.2.0 and JRuby (1.9).
|
|
22
26
|
|
|
23
27
|
Documentation
|
|
24
28
|
-------------
|
|
25
29
|
|
|
26
|
-
Please see the
|
|
27
|
-
[mongoid.org](http://mongoid.org)
|
|
28
|
-
|
|
29
|
-
Donating
|
|
30
|
-
--------
|
|
31
|
-
|
|
32
|
-
[Support Mongoid at Pledgie](http://www.pledgie.com/campaigns/7757)
|
|
33
|
-
|
|
34
|
-
<a href='http://www.pledgie.com/campaigns/7757'>
|
|
35
|
-
<img alt='Click here to lend your support to: Mongoid and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/7757.png?skin_name=chrome' border='0'/>
|
|
36
|
-
</a>
|
|
37
|
-
|
|
38
|
-
[](https://flattr.com/submit/auto?user_id=durran&url=http://github.com/mongoid&title=mongoid&language=&tags=github&category=software)
|
|
30
|
+
Please see the [MongoDB website](http://docs.mongodb.org/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial) for up-to-date documentation on 5.0.0:
|
|
39
31
|
|
|
40
32
|
License
|
|
41
33
|
-------
|
|
42
34
|
|
|
43
|
-
Copyright (c) 2009-
|
|
35
|
+
Copyright (c) 2009-2015 Durran Jordan
|
|
44
36
|
|
|
45
37
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
46
38
|
a copy of this software and associated documentation files (the
|
data/lib/config/locales/en.yml
CHANGED
|
@@ -4,6 +4,9 @@ en:
|
|
|
4
4
|
messages:
|
|
5
5
|
blank_in_locale:
|
|
6
6
|
"can't be blank in %{location}"
|
|
7
|
+
message_title: "message"
|
|
8
|
+
summary_title: "summary"
|
|
9
|
+
resolution_title: "resolution"
|
|
7
10
|
ambiguous_relationship:
|
|
8
11
|
message: "Ambiguous relations %{candidates} defined on %{klass}."
|
|
9
12
|
summary:
|
|
@@ -175,7 +178,7 @@ en:
|
|
|
175
178
|
invalid_storage_options:
|
|
176
179
|
message: "Invalid options passed to %{klass}.store_in: %{options}."
|
|
177
180
|
summary: "The :store_in macro takes only a hash of parameters with
|
|
178
|
-
the keys :database, :collection, or :
|
|
181
|
+
the keys :database, :collection, or :client."
|
|
179
182
|
resolution: "Change the options passed to store_in to match the
|
|
180
183
|
documented API, and ensure all keys in the options hash are
|
|
181
184
|
symbols.\n\n
|
|
@@ -249,9 +252,9 @@ en:
|
|
|
249
252
|
for each parent up the hierarchy."
|
|
250
253
|
resolution: "Consider not embedding %{embedded}, or do the key
|
|
251
254
|
storage and access in a custom manner in the application code."
|
|
252
|
-
|
|
255
|
+
mixed_client_configuration:
|
|
253
256
|
message: "Both uri and standard configuration options defined for
|
|
254
|
-
|
|
257
|
+
client: '%{name}'."
|
|
255
258
|
summary: "Instead of simply giving uri or standard options a
|
|
256
259
|
preference order, Mongoid assumes that you have made a mistake in
|
|
257
260
|
your configuration and requires that you provide one or the other,
|
|
@@ -276,15 +279,15 @@ en:
|
|
|
276
279
|
\_\_\_\_has_many :albums\n
|
|
277
280
|
\_\_\_\_accepts_nested_attributes_for :albums\n
|
|
278
281
|
\_\_end\n\n"
|
|
279
|
-
|
|
280
|
-
message: "No default
|
|
282
|
+
no_default_client:
|
|
283
|
+
message: "No default client configuration is defined."
|
|
281
284
|
summary: "The configuration provided settings for: %{keys}, but
|
|
282
285
|
Mongoid requires a :default to be defined at minimum."
|
|
283
286
|
resolution: "If configuring via a mongoid.yml, ensure that within
|
|
284
|
-
your :
|
|
287
|
+
your :clients section a :default client is defined.\n\n
|
|
285
288
|
Example:\n
|
|
286
289
|
\_\_development:\n
|
|
287
|
-
\_\_\_\
|
|
290
|
+
\_\_\_\_clients:\n
|
|
288
291
|
\_\_\_\_\_\_default:\n
|
|
289
292
|
\_\_\_\_\_\_\_\_hosts:\n
|
|
290
293
|
\_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n"
|
|
@@ -338,59 +341,59 @@ en:
|
|
|
338
341
|
resolution: "Ensure that you've set the parent relation if
|
|
339
342
|
instantiating the embedded document directly, or always create new
|
|
340
343
|
embedded documents via the parent relation."
|
|
341
|
-
|
|
342
|
-
message: "No configuration could be found for a
|
|
344
|
+
no_client_config:
|
|
345
|
+
message: "No configuration could be found for a client named
|
|
343
346
|
'%{name}'."
|
|
344
|
-
summary: "When attempting to create the new
|
|
345
|
-
not find a
|
|
347
|
+
summary: "When attempting to create the new client, Mongoid could
|
|
348
|
+
not find a client configuration for the name: '%{name}'. This is
|
|
346
349
|
necessary in order to know the host, port, and options needed
|
|
347
350
|
to connect."
|
|
348
351
|
resolution: "Double check your mongoid.yml to make sure under the
|
|
349
|
-
|
|
352
|
+
clients key that a configuration exists for '%{name}'. If you
|
|
350
353
|
have set the configuration programatically, ensure that '%{name}'
|
|
351
354
|
exists in the configuration hash."
|
|
352
|
-
|
|
353
|
-
message: "No
|
|
355
|
+
no_clients_config:
|
|
356
|
+
message: "No clients configuration provided."
|
|
354
357
|
summary: "Mongoid's configuration requires that you provide details
|
|
355
|
-
about each
|
|
356
|
-
the
|
|
358
|
+
about each client that can be connected to, and requires in
|
|
359
|
+
the clients config at least 1 default client to exist."
|
|
357
360
|
resolution: "Double check your mongoid.yml to make sure that you
|
|
358
|
-
have a top-level
|
|
361
|
+
have a top-level clients key with at least 1 default client
|
|
359
362
|
configuration for it. You can regenerate a new mongoid.yml for
|
|
360
363
|
assistance via `rails g mongoid:config`.\n\n
|
|
361
364
|
Example:\n
|
|
362
365
|
\_\_development:\n
|
|
363
|
-
\_\_\_\
|
|
366
|
+
\_\_\_\_clients:\n
|
|
364
367
|
\_\_\_\_\_\_default:\n
|
|
365
368
|
\_\_\_\_\_\_\_\_database: mongoid_dev\n
|
|
366
369
|
\_\_\_\_\_\_\_\_hosts:\n
|
|
367
370
|
\_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n"
|
|
368
|
-
|
|
369
|
-
message: "No database provided for
|
|
370
|
-
summary: "Each
|
|
371
|
+
no_client_database:
|
|
372
|
+
message: "No database provided for client configuration: :%{name}."
|
|
373
|
+
summary: "Each client configuration must provide a database so Mongoid
|
|
371
374
|
knows where the default database to persist to. What was provided
|
|
372
375
|
was: %{config}."
|
|
373
376
|
resolution: "If configuring via a mongoid.yml, ensure that within
|
|
374
|
-
your :%{name} section a :database value for the
|
|
377
|
+
your :%{name} section a :database value for the client's default
|
|
375
378
|
database is defined.\n\n
|
|
376
379
|
Example:\n
|
|
377
380
|
\_\_development:\n
|
|
378
|
-
\_\_\_\
|
|
381
|
+
\_\_\_\_clients:\n
|
|
379
382
|
\_\_\_\_\_\_%{name}:\n
|
|
380
383
|
\_\_\_\_\_\_\_\_database: my_app_db\n
|
|
381
384
|
\_\_\_\_\_\_\_\_hosts:\n
|
|
382
385
|
\_\_\_\_\_\_\_\_\_\_- localhost:27017\n\n"
|
|
383
|
-
|
|
384
|
-
message: "No hosts provided for
|
|
385
|
-
summary: "Each
|
|
386
|
+
no_client_hosts:
|
|
387
|
+
message: "No hosts provided for client configuration: :%{name}."
|
|
388
|
+
summary: "Each client configuration must provide hosts so Mongoid
|
|
386
389
|
knows where the database server is located. What was provided
|
|
387
390
|
was: %{config}."
|
|
388
391
|
resolution: "If configuring via a mongoid.yml, ensure that within
|
|
389
|
-
your :%{name} section a :hosts value for the
|
|
392
|
+
your :%{name} section a :hosts value for the client hosts is
|
|
390
393
|
defined.\n\n
|
|
391
394
|
Example:\n
|
|
392
395
|
\_\_development:\n
|
|
393
|
-
\_\_\_\
|
|
396
|
+
\_\_\_\_clients:\n
|
|
394
397
|
\_\_\_\_\_\_%{name}:\n
|
|
395
398
|
\_\_\_\_\_\_\_\_database: my_app_db\n
|
|
396
399
|
\_\_\_\_\_\_\_\_hosts:\n
|
|
@@ -442,8 +445,8 @@ en:
|
|
|
442
445
|
unsaved_document:
|
|
443
446
|
message: "Attempted to save %{document} before the parent %{base}."
|
|
444
447
|
summary: "You cannot call create or create! through the
|
|
445
|
-
relation (%{document})
|
|
446
|
-
not already saved. This would
|
|
448
|
+
relation (%{document}) whose parent (%{base}) is
|
|
449
|
+
not already saved. This would cause the database to be out of sync
|
|
447
450
|
since the child could potentially reference a nonexistant parent."
|
|
448
451
|
resolution: "Make sure to only use create or create! when the parent
|
|
449
452
|
document %{base} is persisted."
|
data/lib/mongoid/atomic.rb
CHANGED
|
@@ -329,9 +329,7 @@ module Mongoid
|
|
|
329
329
|
# @since 3.0.10
|
|
330
330
|
def process_flagged_destroys
|
|
331
331
|
_assigning do
|
|
332
|
-
flagged_destroys.each
|
|
333
|
-
block.call
|
|
334
|
-
end
|
|
332
|
+
flagged_destroys.each(&:call)
|
|
335
333
|
end
|
|
336
334
|
flagged_destroys.clear
|
|
337
335
|
end
|
|
@@ -373,7 +371,7 @@ module Mongoid
|
|
|
373
371
|
# @since 3.0.6
|
|
374
372
|
def touch_atomic_updates(field = nil)
|
|
375
373
|
updates = atomic_updates
|
|
376
|
-
return {} unless atomic_updates.
|
|
374
|
+
return {} unless atomic_updates.key?("$set")
|
|
377
375
|
touches = {}
|
|
378
376
|
updates["$set"].each_pair do |key, value|
|
|
379
377
|
touches.merge!({ key => value }) if key =~ /updated_at|#{field}/
|
|
@@ -92,7 +92,10 @@ module Mongoid
|
|
|
92
92
|
#
|
|
93
93
|
# @since 2.0.0.rc.7
|
|
94
94
|
def process_attribute(name, value)
|
|
95
|
-
|
|
95
|
+
if !respond_to?("#{name}=", true) && store_as = aliased_fields.invert[name.to_s]
|
|
96
|
+
name = store_as
|
|
97
|
+
end
|
|
98
|
+
responds = respond_to?("#{name}=", true)
|
|
96
99
|
raise Errors::UnknownAttribute.new(self.class, name) unless responds
|
|
97
100
|
send("#{name}=", value)
|
|
98
101
|
end
|
|
@@ -23,7 +23,7 @@ module Mongoid
|
|
|
23
23
|
#
|
|
24
24
|
# @since 3.0.0
|
|
25
25
|
def attribute_writable?(name)
|
|
26
|
-
new_record? || !readonly_attributes.include?(name
|
|
26
|
+
new_record? || !readonly_attributes.include?(database_field_name(name))
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
module ClassMethods
|
|
@@ -47,7 +47,7 @@ module Mongoid
|
|
|
47
47
|
# @since 3.0.0
|
|
48
48
|
def attr_readonly(*names)
|
|
49
49
|
names.each do |name|
|
|
50
|
-
readonly_attributes << name
|
|
50
|
+
readonly_attributes << database_field_name(name)
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
end
|
data/lib/mongoid/attributes.rb
CHANGED
|
@@ -58,7 +58,7 @@ module Mongoid
|
|
|
58
58
|
#
|
|
59
59
|
# @since 3.0.0
|
|
60
60
|
def has_attribute?(name)
|
|
61
|
-
attributes.
|
|
61
|
+
attributes.key?(name.to_s)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
# Does the document have the provided attribute before it was assigned
|
|
@@ -74,7 +74,7 @@ module Mongoid
|
|
|
74
74
|
#
|
|
75
75
|
# @since 3.1.0
|
|
76
76
|
def has_attribute_before_type_cast?(name)
|
|
77
|
-
attributes_before_type_cast.
|
|
77
|
+
attributes_before_type_cast.key?(name.to_s)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# Read a value from the document attributes. If the value does not exist
|
|
@@ -119,7 +119,7 @@ module Mongoid
|
|
|
119
119
|
# @since 3.1.0
|
|
120
120
|
def read_attribute_before_type_cast(name)
|
|
121
121
|
attr = name.to_s
|
|
122
|
-
if attributes_before_type_cast.
|
|
122
|
+
if attributes_before_type_cast.key?(attr)
|
|
123
123
|
attributes_before_type_cast[attr]
|
|
124
124
|
else
|
|
125
125
|
read_attribute(attr)
|
|
@@ -256,9 +256,9 @@ module Mongoid
|
|
|
256
256
|
|
|
257
257
|
def selection_included?(name, selection, field)
|
|
258
258
|
if field && field.localized?
|
|
259
|
-
selection.
|
|
259
|
+
selection.key?("#{name}.#{::I18n.locale}")
|
|
260
260
|
else
|
|
261
|
-
selection.
|
|
261
|
+
selection.key?(name)
|
|
262
262
|
end
|
|
263
263
|
end
|
|
264
264
|
|
|
@@ -273,7 +273,7 @@ module Mongoid
|
|
|
273
273
|
#
|
|
274
274
|
# @since 3.0.15
|
|
275
275
|
def hash_dot_syntax?(string)
|
|
276
|
-
string.include?(".")
|
|
276
|
+
string.include?(".".freeze)
|
|
277
277
|
end
|
|
278
278
|
|
|
279
279
|
# Return the typecasted value for a field.
|
|
@@ -288,7 +288,7 @@ module Mongoid
|
|
|
288
288
|
#
|
|
289
289
|
# @since 1.0.0
|
|
290
290
|
def typed_value_for(key, value)
|
|
291
|
-
fields.
|
|
291
|
+
fields.key?(key) ? fields[key].mongoize(value) : value.mongoize
|
|
292
292
|
end
|
|
293
293
|
|
|
294
294
|
module ClassMethods
|
data/lib/mongoid/changeable.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Mongoid
|
|
|
16
16
|
#
|
|
17
17
|
# @since 2.4.0
|
|
18
18
|
def changed
|
|
19
|
-
changed_attributes.keys
|
|
19
|
+
changed_attributes.keys.select { |attr| attribute_change(attr) }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
# Has the document changed?
|
|
@@ -40,9 +40,7 @@ module Mongoid
|
|
|
40
40
|
#
|
|
41
41
|
# @since 2.4.1
|
|
42
42
|
def children_changed?
|
|
43
|
-
_children.any?
|
|
44
|
-
child.changed?
|
|
45
|
-
end
|
|
43
|
+
_children.any?(&:changed?)
|
|
46
44
|
end
|
|
47
45
|
|
|
48
46
|
# Get the attribute changes.
|
|
@@ -184,7 +182,7 @@ module Mongoid
|
|
|
184
182
|
# @since 2.1.6
|
|
185
183
|
def attribute_changed?(attr)
|
|
186
184
|
attr = database_field_name(attr)
|
|
187
|
-
return false unless changed_attributes.
|
|
185
|
+
return false unless changed_attributes.key?(attr)
|
|
188
186
|
changed_attributes[attr] != attributes[attr]
|
|
189
187
|
end
|
|
190
188
|
|
|
@@ -228,7 +226,7 @@ module Mongoid
|
|
|
228
226
|
#
|
|
229
227
|
# @since 2.3.0
|
|
230
228
|
def attribute_will_change!(attr)
|
|
231
|
-
unless changed_attributes.
|
|
229
|
+
unless changed_attributes.key?(attr)
|
|
232
230
|
changed_attributes[attr] = read_attribute(attr).__deep_copy__
|
|
233
231
|
end
|
|
234
232
|
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Clients
|
|
5
|
+
module Factory
|
|
6
|
+
extend self
|
|
7
|
+
|
|
8
|
+
# Create a new client given the named configuration. If no name is
|
|
9
|
+
# provided, return a new client with the default configuration. If a
|
|
10
|
+
# name is provided for which no configuration exists, an error will be
|
|
11
|
+
# raised.
|
|
12
|
+
#
|
|
13
|
+
# @example Create the client.
|
|
14
|
+
# Factory.create(:secondary)
|
|
15
|
+
#
|
|
16
|
+
# @param [ String, Symbol ] name The named client configuration.
|
|
17
|
+
#
|
|
18
|
+
# @raise [ Errors::NoClientConfig ] If no config could be found.
|
|
19
|
+
#
|
|
20
|
+
# @return [ Mongo::Client ] The new client.
|
|
21
|
+
#
|
|
22
|
+
# @since 3.0.0
|
|
23
|
+
def create(name = nil)
|
|
24
|
+
return default unless name
|
|
25
|
+
config = Mongoid.clients[name]
|
|
26
|
+
raise Errors::NoClientConfig.new(name) unless config
|
|
27
|
+
create_client(config)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Get the default client.
|
|
31
|
+
#
|
|
32
|
+
# @example Get the default client.
|
|
33
|
+
# Factory.default
|
|
34
|
+
#
|
|
35
|
+
# @raise [ Errors::NoClientConfig ] If no default configuration is
|
|
36
|
+
# found.
|
|
37
|
+
#
|
|
38
|
+
# @return [ Mongo::Client ] The default client.
|
|
39
|
+
#
|
|
40
|
+
# @since 3.0.0
|
|
41
|
+
def default
|
|
42
|
+
create_client(Mongoid.clients[:default])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# Create the client for the provided config.
|
|
48
|
+
#
|
|
49
|
+
# @api private
|
|
50
|
+
#
|
|
51
|
+
# @example Create the client.
|
|
52
|
+
# Factory.create_client(config)
|
|
53
|
+
#
|
|
54
|
+
# @param [ Hash ] configuration The client config.
|
|
55
|
+
#
|
|
56
|
+
# @return [ Mongo::Client ] The client.
|
|
57
|
+
#
|
|
58
|
+
# @since 3.0.0
|
|
59
|
+
def create_client(configuration)
|
|
60
|
+
raise Errors::NoClientsConfig.new unless configuration
|
|
61
|
+
if configuration[:uri]
|
|
62
|
+
Mongo::Client.new(configuration[:uri], options(configuration))
|
|
63
|
+
else
|
|
64
|
+
Mongo::Client.new(
|
|
65
|
+
configuration[:hosts],
|
|
66
|
+
options(configuration).merge(database: configuration[:database])
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def options(configuration)
|
|
72
|
+
config = configuration.dup
|
|
73
|
+
options = config.delete(:options) || {}
|
|
74
|
+
options.reject{ |k, v| k == :hosts }.to_hash.symbolize_keys!
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
module Mongoid
|
|
3
|
-
module
|
|
3
|
+
module Clients
|
|
4
4
|
module Options
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
|
+
extend Gem::Deprecate
|
|
6
7
|
|
|
7
8
|
# Tell the next persistance operation to store in a specific collection,
|
|
8
|
-
# database or
|
|
9
|
+
# database or client.
|
|
9
10
|
#
|
|
10
11
|
# @example Save the current document to a different collection.
|
|
11
12
|
# model.with(collection: "secondary").save
|
|
@@ -13,17 +14,22 @@ module Mongoid
|
|
|
13
14
|
# @example Save the current document to a different database.
|
|
14
15
|
# model.with(database: "secondary").save
|
|
15
16
|
#
|
|
16
|
-
# @example Save the current document to a different
|
|
17
|
-
# model.with(
|
|
17
|
+
# @example Save the current document to a different client.
|
|
18
|
+
# model.with(client: "replica_set").save
|
|
18
19
|
#
|
|
19
20
|
# @example Save with a combination of options.
|
|
20
|
-
# model.with(
|
|
21
|
+
# model.with(client: "sharded", database: "secondary").save
|
|
22
|
+
#
|
|
23
|
+
# @note This method will instantiate a new client under the covers and
|
|
24
|
+
# can be expensive. It is also recommended that the user manually
|
|
25
|
+
# closes the extra client after using it, otherwise an excessive amount
|
|
26
|
+
# of connections to the server will be eventually opened.
|
|
21
27
|
#
|
|
22
28
|
# @param [ Hash ] options The storage options.
|
|
23
29
|
#
|
|
24
30
|
# @option options [ String, Symbol ] :collection The collection name.
|
|
25
31
|
# @option options [ String, Symbol ] :database The database name.
|
|
26
|
-
# @option options [ String, Symbol ] :
|
|
32
|
+
# @option options [ String, Symbol ] :client The client name.
|
|
27
33
|
#
|
|
28
34
|
# @return [ Document ] The current document.
|
|
29
35
|
#
|
|
@@ -37,17 +43,19 @@ module Mongoid
|
|
|
37
43
|
@persistence_options
|
|
38
44
|
end
|
|
39
45
|
|
|
40
|
-
def
|
|
46
|
+
def mongo_client
|
|
41
47
|
if persistence_options
|
|
42
|
-
if persistence_options[:
|
|
43
|
-
|
|
48
|
+
if persistence_options[:client]
|
|
49
|
+
client = Clients.with_name(persistence_options[:client])
|
|
44
50
|
else
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
client = Clients.with_name(self.class.client_name)
|
|
52
|
+
client.use(self.class.database_name)
|
|
47
53
|
end
|
|
48
|
-
|
|
54
|
+
client.with(persistence_options.reject{ |k, v| k == :collection || k == :client })
|
|
49
55
|
end
|
|
50
56
|
end
|
|
57
|
+
alias :mongo_session :mongo_client
|
|
58
|
+
deprecate :mongo_session, :mongo_client, 2015, 12
|
|
51
59
|
|
|
52
60
|
def collection_name
|
|
53
61
|
if persistence_options && v = persistence_options[:collection]
|
|
@@ -91,14 +99,17 @@ module Mongoid
|
|
|
91
99
|
end
|
|
92
100
|
|
|
93
101
|
module ClassMethods
|
|
102
|
+
extend Gem::Deprecate
|
|
94
103
|
include Threaded
|
|
95
104
|
|
|
96
|
-
def
|
|
97
|
-
if persistence_options && v = persistence_options[:
|
|
105
|
+
def client_name
|
|
106
|
+
if persistence_options && v = persistence_options[:client]
|
|
98
107
|
return v.to_sym
|
|
99
108
|
end
|
|
100
109
|
super
|
|
101
110
|
end
|
|
111
|
+
alias :session_name :client_name
|
|
112
|
+
deprecate :session_name, :client_name, 2015, 12
|
|
102
113
|
|
|
103
114
|
def collection_name
|
|
104
115
|
if persistence_options && v = persistence_options[:collection]
|
|
@@ -115,7 +126,7 @@ module Mongoid
|
|
|
115
126
|
end
|
|
116
127
|
|
|
117
128
|
# Tell the next persistance operation to store in a specific collection,
|
|
118
|
-
# database or
|
|
129
|
+
# database or client.
|
|
119
130
|
#
|
|
120
131
|
# @example Create a document in a different collection.
|
|
121
132
|
# Model.with(collection: "secondary").create(name: "test")
|
|
@@ -123,17 +134,17 @@ module Mongoid
|
|
|
123
134
|
# @example Create a document in a different database.
|
|
124
135
|
# Model.with(database: "secondary").create(name: "test")
|
|
125
136
|
#
|
|
126
|
-
# @example Create a document in a different
|
|
127
|
-
# Model.with(
|
|
137
|
+
# @example Create a document in a different client.
|
|
138
|
+
# Model.with(client: "secondary").create(name: "test")
|
|
128
139
|
#
|
|
129
140
|
# @example Create with a combination of options.
|
|
130
|
-
# Model.with(
|
|
141
|
+
# Model.with(client: "sharded", database: "secondary").create
|
|
131
142
|
#
|
|
132
143
|
# @param [ Hash ] options The storage options.
|
|
133
144
|
#
|
|
134
145
|
# @option options [ String, Symbol ] :collection The collection name.
|
|
135
146
|
# @option options [ String, Symbol ] :database The database name.
|
|
136
|
-
# @option options [ String, Symbol ] :
|
|
147
|
+
# @option options [ String, Symbol ] :client The client name.
|
|
137
148
|
#
|
|
138
149
|
# @return [ Class ] The model class.
|
|
139
150
|
#
|