mongoid 7.6.2 → 8.0.1
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
- checksums.yaml.gz.sig +2 -0
- data/README.md +3 -3
- data/Rakefile +21 -85
- data/lib/config/locales/en.yml +46 -56
- data/lib/mongoid/association/accessors.rb +32 -3
- data/lib/mongoid/association/bindable.rb +48 -0
- data/lib/mongoid/association/builders.rb +4 -2
- data/lib/mongoid/association/depending.rb +4 -8
- data/lib/mongoid/association/eager_loadable.rb +29 -7
- data/lib/mongoid/association/embedded/batchable.rb +28 -5
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
- data/lib/mongoid/association/embedded/embedded_in.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +40 -18
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +18 -4
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +21 -2
- data/lib/mongoid/association/macros.rb +2 -1
- data/lib/mongoid/association/many.rb +5 -0
- data/lib/mongoid/association/nested/many.rb +5 -39
- data/lib/mongoid/association/nested/nested_buildable.rb +0 -14
- data/lib/mongoid/association/proxy.rb +12 -0
- data/lib/mongoid/association/referenced/auto_save.rb +3 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
- data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +8 -8
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +64 -11
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +4 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -18
- data/lib/mongoid/association/referenced/has_many/proxy.rb +11 -107
- data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
- data/lib/mongoid/association/referenced/has_one/proxy.rb +8 -11
- data/lib/mongoid/association/referenced/syncable.rb +2 -2
- data/lib/mongoid/association/relatable.rb +38 -4
- data/lib/mongoid/attributes/processing.rb +9 -2
- data/lib/mongoid/attributes.rb +30 -27
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/changeable.rb +37 -2
- data/lib/mongoid/clients/factory.rb +0 -4
- data/lib/mongoid/clients/options.rb +4 -0
- data/lib/mongoid/clients/sessions.rb +2 -14
- data/lib/mongoid/config.rb +15 -73
- data/lib/mongoid/contextual/aggregable/memory.rb +22 -20
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +2 -2
- data/lib/mongoid/contextual/memory.rb +63 -47
- data/lib/mongoid/contextual/mongo.rb +173 -287
- data/lib/mongoid/contextual/none.rb +33 -15
- data/lib/mongoid/copyable.rb +32 -8
- data/lib/mongoid/criteria/includable.rb +24 -20
- data/lib/mongoid/criteria/marshalable.rb +10 -2
- data/lib/mongoid/criteria/queryable/extensions/array.rb +2 -15
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +0 -16
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
- data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +0 -12
- data/lib/mongoid/criteria/queryable/optional.rb +3 -9
- data/lib/mongoid/criteria/queryable/options.rb +1 -1
- data/lib/mongoid/criteria/queryable/selectable.rb +2 -133
- data/lib/mongoid/criteria/queryable/selector.rb +90 -5
- data/lib/mongoid/criteria/queryable/smash.rb +39 -6
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria/queryable.rb +11 -6
- data/lib/mongoid/criteria.rb +1 -28
- data/lib/mongoid/deprecable.rb +36 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +88 -33
- data/lib/mongoid/equality.rb +4 -4
- data/lib/mongoid/errors/document_not_found.rb +6 -2
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_field.rb +5 -1
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
- data/lib/mongoid/errors.rb +2 -3
- data/lib/mongoid/extensions/array.rb +8 -6
- data/lib/mongoid/extensions/big_decimal.rb +29 -10
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +8 -2
- data/lib/mongoid/extensions/date.rb +26 -20
- data/lib/mongoid/extensions/date_time.rb +1 -1
- data/lib/mongoid/extensions/float.rb +4 -5
- data/lib/mongoid/extensions/hash.rb +13 -32
- data/lib/mongoid/extensions/integer.rb +4 -5
- data/lib/mongoid/extensions/object.rb +2 -0
- data/lib/mongoid/extensions/range.rb +41 -10
- data/lib/mongoid/extensions/regexp.rb +11 -4
- data/lib/mongoid/extensions/set.rb +11 -4
- data/lib/mongoid/extensions/string.rb +2 -13
- data/lib/mongoid/extensions/symbol.rb +3 -14
- data/lib/mongoid/extensions/time.rb +27 -16
- data/lib/mongoid/extensions/time_with_zone.rb +1 -2
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/factory.rb +42 -7
- data/lib/mongoid/fields/foreign_key.rb +7 -0
- data/lib/mongoid/fields/validators/macro.rb +3 -9
- data/lib/mongoid/fields.rb +49 -7
- data/lib/mongoid/findable.rb +21 -16
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +4 -1
- data/lib/mongoid/interceptable.rb +69 -9
- data/lib/mongoid/matchable.rb +1 -6
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +5 -3
- data/lib/mongoid/matcher/regex.rb +9 -8
- data/lib/mongoid/matcher.rb +0 -1
- data/lib/mongoid/persistable/creatable.rb +14 -5
- data/lib/mongoid/persistable/updatable.rb +12 -5
- data/lib/mongoid/persistence_context.rb +8 -42
- data/lib/mongoid/query_cache.rb +6 -258
- data/lib/mongoid/railties/controller_runtime.rb +1 -1
- data/lib/mongoid/reloadable.rb +7 -3
- data/lib/mongoid/scopable.rb +9 -11
- data/lib/mongoid/selectable.rb +1 -2
- data/lib/mongoid/shardable.rb +11 -35
- data/lib/mongoid/stateful.rb +27 -1
- data/lib/mongoid/threaded.rb +0 -3
- data/lib/mongoid/timestamps/created.rb +1 -1
- data/lib/mongoid/timestamps/updated.rb +1 -1
- data/lib/mongoid/touchable.rb +2 -3
- data/lib/mongoid/traversable.rb +1 -0
- data/lib/mongoid/validatable/uniqueness.rb +2 -1
- data/lib/mongoid/version.rb +1 -5
- data/lib/mongoid/warnings.rb +3 -5
- data/lib/mongoid.rb +1 -0
- data/spec/config/mongoid.yml +16 -0
- data/spec/integration/app_spec.rb +8 -20
- data/spec/integration/associations/belongs_to_spec.rb +18 -0
- data/spec/integration/associations/embedded_spec.rb +15 -0
- data/spec/integration/associations/embeds_many_spec.rb +15 -2
- data/spec/integration/associations/embeds_one_spec.rb +18 -0
- data/spec/integration/associations/foreign_key_spec.rb +9 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_one_spec.rb +97 -1
- data/spec/integration/associations/scope_option_spec.rb +1 -1
- data/spec/integration/callbacks_models.rb +95 -1
- data/spec/integration/callbacks_spec.rb +226 -4
- data/spec/integration/criteria/range_spec.rb +95 -1
- data/spec/integration/discriminator_key_spec.rb +115 -76
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +1 -15
- data/spec/integration/matcher_examples_spec.rb +20 -13
- data/spec/integration/matcher_operator_data/regex.yml +0 -21
- data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
- data/spec/integration/matcher_operator_spec.rb +3 -5
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/mongoid/association/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +9 -9
- data/spec/mongoid/association/eager_spec.rb +2 -1
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +69 -9
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +198 -8
- data/spec/mongoid/association/embedded/embeds_many_models.rb +36 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +15 -0
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +36 -51
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2 -56
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +60 -156
- data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
- data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
- data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
- data/spec/mongoid/association/syncable_spec.rb +14 -0
- data/spec/mongoid/atomic/paths_spec.rb +0 -14
- data/spec/mongoid/attributes/nested_spec.rb +73 -198
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_spec.rb +1 -5
- data/spec/mongoid/attributes_spec.rb +480 -27
- data/spec/mongoid/cacheable_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +130 -13
- data/spec/mongoid/clients/factory_spec.rb +22 -60
- data/spec/mongoid/clients/sessions_spec.rb +0 -38
- data/spec/mongoid/clients_spec.rb +2 -2
- data/spec/mongoid/config_spec.rb +52 -15
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +371 -231
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
- data/spec/mongoid/contextual/memory_spec.rb +467 -156
- data/spec/mongoid/contextual/mongo_spec.rb +566 -426
- data/spec/mongoid/contextual/none_spec.rb +11 -19
- data/spec/mongoid/copyable_spec.rb +451 -2
- data/spec/mongoid/criteria/findable_spec.rb +86 -210
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +0 -484
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +50 -2
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +77 -85
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +0 -200
- data/spec/mongoid/criteria/queryable/selector_spec.rb +16 -77
- data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
- data/spec/mongoid/criteria_spec.rb +469 -1203
- data/spec/mongoid/document_fields_spec.rb +173 -24
- data/spec/mongoid/document_spec.rb +32 -41
- data/spec/mongoid/equality_spec.rb +12 -12
- data/spec/mongoid/errors/document_not_found_spec.rb +29 -2
- data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
- data/spec/mongoid/errors/no_environment_spec.rb +3 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
- data/spec/mongoid/extensions/array_spec.rb +16 -2
- data/spec/mongoid/extensions/big_decimal_spec.rb +697 -212
- data/spec/mongoid/extensions/binary_spec.rb +44 -9
- data/spec/mongoid/extensions/boolean_spec.rb +68 -82
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
- data/spec/mongoid/extensions/date_spec.rb +71 -1
- data/spec/mongoid/extensions/date_time_spec.rb +15 -9
- data/spec/mongoid/extensions/float_spec.rb +48 -76
- data/spec/mongoid/extensions/hash_spec.rb +30 -236
- data/spec/mongoid/extensions/integer_spec.rb +45 -66
- data/spec/mongoid/extensions/range_spec.rb +255 -54
- data/spec/mongoid/extensions/regexp_spec.rb +58 -33
- data/spec/mongoid/extensions/set_spec.rb +106 -0
- data/spec/mongoid/extensions/string_spec.rb +53 -25
- data/spec/mongoid/extensions/symbol_spec.rb +18 -25
- data/spec/mongoid/extensions/time_spec.rb +634 -66
- data/spec/mongoid/extensions/time_with_zone_spec.rb +17 -31
- data/spec/mongoid/factory_spec.rb +61 -1
- data/spec/mongoid/fields_spec.rb +321 -50
- data/spec/mongoid/findable_spec.rb +64 -29
- data/spec/mongoid/indexable/specification_spec.rb +2 -2
- data/spec/mongoid/indexable_spec.rb +16 -19
- data/spec/mongoid/interceptable_spec.rb +584 -5
- data/spec/mongoid/interceptable_spec_models.rb +235 -4
- data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +2 -2
- data/spec/mongoid/persistable/destroyable_spec.rb +2 -2
- data/spec/mongoid/persistable/upsertable_spec.rb +14 -0
- data/spec/mongoid/persistence_context_spec.rb +24 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
- data/spec/mongoid/query_cache_spec.rb +1 -156
- data/spec/mongoid/reloadable_spec.rb +35 -2
- data/spec/mongoid/scopable_spec.rb +36 -34
- data/spec/mongoid/serializable_spec.rb +14 -7
- data/spec/mongoid/shardable_models.rb +0 -14
- data/spec/mongoid/shardable_spec.rb +61 -153
- data/spec/mongoid/stateful_spec.rb +28 -0
- data/spec/mongoid/timestamps_spec.rb +390 -0
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +116 -0
- data/spec/mongoid/touchable_spec_models.rb +12 -8
- data/spec/mongoid/traversable_spec.rb +4 -11
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +60 -31
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +1 -7
- data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
- data/spec/rails/mongoid_spec.rb +4 -16
- data/spec/shared/lib/mrss/cluster_config.rb +40 -5
- data/spec/shared/lib/mrss/constraints.rb +46 -7
- data/spec/shared/lib/mrss/docker_runner.rb +21 -17
- data/spec/shared/lib/mrss/eg_config_utils.rb +31 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +5 -15
- data/spec/shared/lib/mrss/lite_constraints.rb +2 -10
- data/spec/shared/lib/mrss/server_version_registry.rb +29 -18
- data/spec/shared/lib/mrss/spec_organizer.rb +3 -32
- data/spec/shared/lib/mrss/utils.rb +6 -28
- data/spec/shared/share/Dockerfile.erb +114 -38
- data/spec/shared/shlib/distro.sh +0 -10
- data/spec/shared/shlib/server.sh +83 -64
- data/spec/shared/shlib/set_env.sh +81 -16
- data/spec/support/constraints.rb +24 -0
- data/spec/support/expectations.rb +17 -20
- data/spec/support/macros.rb +30 -0
- data/spec/support/models/augmentation.rb +12 -0
- data/spec/support/models/band.rb +3 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/circus.rb +3 -0
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/support/models/implant.rb +9 -0
- data/spec/support/models/label.rb +2 -0
- data/spec/support/models/passport.rb +9 -0
- data/spec/support/models/person.rb +1 -0
- data/spec/support/models/player.rb +2 -0
- data/spec/support/models/powerup.rb +12 -0
- data/spec/support/models/registry.rb +1 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/shield.rb +18 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/weapon.rb +12 -0
- data.tar.gz.sig +0 -0
- metadata +695 -650
- metadata.gz.sig +0 -0
- data/lib/mongoid/errors/eager_load.rb +0 -23
- data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
- data/lib/mongoid/errors/invalid_value.rb +0 -17
- data/lib/mongoid/field_readable.rb +0 -70
- data/lib/mongoid/matcher/regexp_budget.rb +0 -389
- data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
- data/spec/integration/query_operator_guard_spec.rb +0 -89
- data/spec/mongoid/errors/eager_load_spec.rb +0 -31
- data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
- data/spec/shared/CANDIDATE.md +0 -28
- data/spec/shared/lib/mrss/release/candidate.rb +0 -287
- data/spec/shared/lib/mrss/release/product_data.rb +0 -144
- data/spec/shared/lib/tasks/candidate.rake +0 -64
data/lib/mongoid/config.rb
CHANGED
|
@@ -75,114 +75,55 @@ module Mongoid
|
|
|
75
75
|
# Return stored times as UTC.
|
|
76
76
|
option :use_utc, default: false
|
|
77
77
|
|
|
78
|
+
# Store BigDecimals as Decimal128s instead of strings in the db.
|
|
79
|
+
option :map_big_decimal_to_decimal128, default: true
|
|
80
|
+
|
|
78
81
|
# Update embedded documents correctly when setting it, unsetting it
|
|
79
82
|
# and resetting it. See MONGOID-5206 and MONGOID-5240 for more details.
|
|
80
|
-
option :broken_updates, default:
|
|
83
|
+
option :broken_updates, default: false
|
|
81
84
|
|
|
82
85
|
# Maintain legacy behavior of === on Mongoid documents, which returns
|
|
83
86
|
# true in a number of cases where Ruby's === implementation would
|
|
84
87
|
# return false.
|
|
85
|
-
option :legacy_triple_equals, default:
|
|
88
|
+
option :legacy_triple_equals, default: false
|
|
86
89
|
|
|
87
90
|
# When exiting a nested `with_scope' block, set the current scope to
|
|
88
91
|
# nil instead of the parent scope for backwards compatibility.
|
|
89
|
-
option :broken_scoping, default:
|
|
92
|
+
option :broken_scoping, default: false
|
|
90
93
|
|
|
91
94
|
# Maintain broken behavior of sum over empty result sets for backwards
|
|
92
95
|
# compatibility.
|
|
93
|
-
option :broken_aggregables, default:
|
|
96
|
+
option :broken_aggregables, default: false
|
|
94
97
|
|
|
95
98
|
# Ignore aliased fields in embedded documents when performing pluck and
|
|
96
99
|
# distinct operations, for backwards compatibility.
|
|
97
|
-
option :broken_alias_handling, default:
|
|
100
|
+
option :broken_alias_handling, default: false
|
|
98
101
|
|
|
99
102
|
# Maintain broken `and' behavior when using the same operator on the same
|
|
100
103
|
# field multiple times for backwards compatibility.
|
|
101
|
-
option :broken_and, default:
|
|
104
|
+
option :broken_and, default: false
|
|
102
105
|
|
|
103
106
|
# Use millisecond precision when comparing Time objects with the _matches?
|
|
104
107
|
# function.
|
|
105
|
-
option :compare_time_by_ms, default:
|
|
108
|
+
option :compare_time_by_ms, default: true
|
|
106
109
|
|
|
107
110
|
# Use bson-ruby's implementation of as_json for BSON::ObjectId instead of
|
|
108
111
|
# the one monkey-patched into Mongoid.
|
|
109
|
-
option :object_id_as_json_oid, default:
|
|
112
|
+
option :object_id_as_json_oid, default: false
|
|
110
113
|
|
|
111
114
|
# Maintain legacy behavior of pluck and distinct, which does not
|
|
112
115
|
# demongoize the values on returning them.
|
|
113
|
-
option :legacy_pluck_distinct, default:
|
|
116
|
+
option :legacy_pluck_distinct, default: false
|
|
114
117
|
|
|
115
118
|
# Combine chained operators, which use the same field and operator,
|
|
116
119
|
# using and's instead of overwriting them.
|
|
117
|
-
option :overwrite_chained_operators, default:
|
|
120
|
+
option :overwrite_chained_operators, default: false
|
|
118
121
|
|
|
119
122
|
# When this flag is true, the attributes method on a document will return
|
|
120
123
|
# a BSON::Document when that document is retrieved from the database, and
|
|
121
124
|
# a Hash otherwise. When this flag is false, the attributes method will
|
|
122
125
|
# always return a Hash.
|
|
123
|
-
option :legacy_attributes, default:
|
|
124
|
-
|
|
125
|
-
# The maximum number of seconds that evaluating a single query in memory
|
|
126
|
-
# may spend executing regular expressions. Queries against an embedded
|
|
127
|
-
# association are evaluated in the calling thread, so a pattern built from
|
|
128
|
-
# user input runs locally and can otherwise consume unbounded CPU. The
|
|
129
|
-
# limit is cumulative over the whole query, since cost grows with the
|
|
130
|
-
# number of documents and conditions as well as with the pattern.
|
|
131
|
-
#
|
|
132
|
-
# Set to nil to remove the limit. On Ruby 3.2 and later the remaining
|
|
133
|
-
# budget is compiled into the pattern, so the limit counts only the time
|
|
134
|
-
# spent matching. Earlier Rubies have no per-Regexp timeout, so the query
|
|
135
|
-
# is bounded with Timeout instead and the limit is wall clock over the
|
|
136
|
-
# whole in-memory evaluation.
|
|
137
|
-
#
|
|
138
|
-
# See https://jira.mongodb.org/browse/MONGOID-5981 for details.
|
|
139
|
-
option :in_memory_regexp_time_limit, default: 5.0
|
|
140
|
-
|
|
141
|
-
# When false (default), query operators are restricted when building a
|
|
142
|
-
# selector, so that user-supplied input reaching the query builder cannot
|
|
143
|
-
# make MongoDB execute arbitrary JavaScript. Two rules are enforced:
|
|
144
|
-
#
|
|
145
|
-
# - An operator at the top level of an expression must appear in
|
|
146
|
-
# +Criteria::Queryable::Selectable::ALLOWED_QUERY_OPERATORS+.
|
|
147
|
-
# - +$where+, +$function+, and +$accumulator+ are rejected at any depth,
|
|
148
|
-
# including inside +$expr+ and the logical operators.
|
|
149
|
-
#
|
|
150
|
-
# This applies to every query method that accepts an expression, including
|
|
151
|
-
# +where+, +find_by+, +and+, +or+, +nor+, +not+, +any_of+, and +none_of+.
|
|
152
|
-
# It also governs the string form of +where+, e.g.
|
|
153
|
-
# +where("this.name == 'admin'")+, which the server evaluates as +$where+.
|
|
154
|
-
# Applications relying on that form must set this option to true.
|
|
155
|
-
#
|
|
156
|
-
# The APIs that request JavaScript explicitly, +Criteria#for_js+ and
|
|
157
|
-
# +js_query+, are unaffected: there the developer has asked for it.
|
|
158
|
-
#
|
|
159
|
-
# Set to true to restore the unrestricted pass-through behavior.
|
|
160
|
-
#
|
|
161
|
-
# Note that this option is deliberately not tied to +load_defaults+: an
|
|
162
|
-
# application that has opted into older defaults still gets the guard, and
|
|
163
|
-
# must set this option explicitly to turn it off.
|
|
164
|
-
#
|
|
165
|
-
# See https://jira.mongodb.org/browse/MONGOID-5939,
|
|
166
|
-
# https://jira.mongodb.org/browse/MONGOID-5993,
|
|
167
|
-
# https://jira.mongodb.org/browse/MONGOID-5994 for details.
|
|
168
|
-
option :allow_unsafe_query_operators, default: false
|
|
169
|
-
|
|
170
|
-
# When this flag is true, it will be possible to add a record to a
|
|
171
|
-
# "has_many" or "has_and_belongs_to_many" association by passing that
|
|
172
|
-
# record's id in the nested attributes for another parent record, even
|
|
173
|
-
# when the record does not already belong to that association. For a
|
|
174
|
-
# "has_many" association this moves the record to the new parent.
|
|
175
|
-
#
|
|
176
|
-
# When this flag is false, an id in nested attributes is only resolved
|
|
177
|
-
# within the association itself, and anything else raises an error.
|
|
178
|
-
#
|
|
179
|
-
# The default is `false`. Note that allowing reparenting via nested attributes
|
|
180
|
-
# is a potential security risk, since it could allow a malicious user to move
|
|
181
|
-
# records that they do not own to a parent record that they do own.
|
|
182
|
-
#
|
|
183
|
-
# This option will be removed in Mongoid 10, and the only behavior will be
|
|
184
|
-
# as if this option were set to false.
|
|
185
|
-
option :allow_reparenting_via_nested_attributes, default: false
|
|
126
|
+
option :legacy_attributes, default: false
|
|
186
127
|
|
|
187
128
|
# Has Mongoid been configured? This is checking that at least a valid
|
|
188
129
|
# client config exists.
|
|
@@ -275,6 +216,7 @@ module Mongoid
|
|
|
275
216
|
configuration = settings.with_indifferent_access
|
|
276
217
|
self.options = configuration[:options]
|
|
277
218
|
self.clients = configuration[:clients]
|
|
219
|
+
Mongo.options = configuration[:driver_options] || {}
|
|
278
220
|
set_log_levels
|
|
279
221
|
end
|
|
280
222
|
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mongoid/field_readable'
|
|
4
|
-
|
|
5
3
|
module Mongoid
|
|
6
4
|
module Contextual
|
|
7
5
|
module Aggregable
|
|
8
6
|
# Contains behavior for aggregating values in memory.
|
|
9
7
|
module Memory
|
|
10
|
-
include FieldReadable
|
|
11
8
|
|
|
12
9
|
# Get all the aggregate values for the provided field.
|
|
13
10
|
# Provided for interface consistency with Aggregable::Mongo.
|
|
@@ -30,9 +27,13 @@ module Mongoid
|
|
|
30
27
|
#
|
|
31
28
|
# @param [ Symbol ] field The field to average.
|
|
32
29
|
#
|
|
33
|
-
# @return [
|
|
30
|
+
# @return [ Numeric ] The average.
|
|
34
31
|
def avg(field)
|
|
35
|
-
count
|
|
32
|
+
total = count { |doc| !doc.send(field).nil? }
|
|
33
|
+
return nil unless total > 0
|
|
34
|
+
|
|
35
|
+
total = total.to_f if total.is_a?(Integer)
|
|
36
|
+
sum(field) / total
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
# Get the max value of the provided field. If provided a block, will
|
|
@@ -49,10 +50,12 @@ module Mongoid
|
|
|
49
50
|
#
|
|
50
51
|
# @param [ Symbol ] field The field to max.
|
|
51
52
|
#
|
|
52
|
-
# @return [
|
|
53
|
+
# @return [ Numeric | Document ] The max value or document with the max
|
|
53
54
|
# value.
|
|
54
55
|
def max(field = nil)
|
|
55
|
-
|
|
56
|
+
return super() if block_given?
|
|
57
|
+
|
|
58
|
+
aggregate_by(field, :max)
|
|
56
59
|
end
|
|
57
60
|
|
|
58
61
|
# Get the min value of the provided field. If provided a block, will
|
|
@@ -69,10 +72,12 @@ module Mongoid
|
|
|
69
72
|
#
|
|
70
73
|
# @param [ Symbol ] field The field to min.
|
|
71
74
|
#
|
|
72
|
-
# @return [
|
|
75
|
+
# @return [ Numeric | Document ] The min value or document with the min
|
|
73
76
|
# value.
|
|
74
77
|
def min(field = nil)
|
|
75
|
-
|
|
78
|
+
return super() if block_given?
|
|
79
|
+
|
|
80
|
+
aggregate_by(field, :min)
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
# Get the sum value of the provided field. If provided a block, will
|
|
@@ -86,13 +91,11 @@ module Mongoid
|
|
|
86
91
|
#
|
|
87
92
|
# @param [ Symbol ] field The field to sum.
|
|
88
93
|
#
|
|
89
|
-
# @return [
|
|
94
|
+
# @return [ Numeric ] The sum value.
|
|
90
95
|
def sum(field = nil)
|
|
91
|
-
if block_given?
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
count > 0 ? map { |doc| read_field_value(doc, field) }.compact.sum : 0
|
|
95
|
-
end
|
|
96
|
+
return super() if block_given?
|
|
97
|
+
|
|
98
|
+
aggregate_by(field, :sum) || 0
|
|
96
99
|
end
|
|
97
100
|
|
|
98
101
|
private
|
|
@@ -102,17 +105,16 @@ module Mongoid
|
|
|
102
105
|
# @api private
|
|
103
106
|
#
|
|
104
107
|
# @example Aggregate by the field and method.
|
|
105
|
-
# aggregable.aggregate_by(:
|
|
108
|
+
# aggregable.aggregate_by(:likes, :min_by)
|
|
106
109
|
#
|
|
107
110
|
# @param [ Symbol ] field The field to aggregate on.
|
|
108
111
|
# @param [ Symbol ] method The method (min_by or max_by).
|
|
109
112
|
#
|
|
110
|
-
# @return [
|
|
113
|
+
# @return [ Numeric | nil ] The aggregate.
|
|
111
114
|
def aggregate_by(field, method)
|
|
112
|
-
return nil
|
|
115
|
+
return nil unless any?
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
read_field_value(doc, field)
|
|
117
|
+
map { |doc| doc.public_send(field) }.compact.public_send(method)
|
|
116
118
|
end
|
|
117
119
|
end
|
|
118
120
|
end
|
|
@@ -26,7 +26,7 @@ module Mongoid
|
|
|
26
26
|
# If no documents are found, then returned Hash will have
|
|
27
27
|
# count, sum of 0 and max, min, avg of nil.
|
|
28
28
|
def aggregates(field)
|
|
29
|
-
result = collection.
|
|
29
|
+
result = collection.aggregate(pipeline(field), session: _session).to_a
|
|
30
30
|
if result.empty?
|
|
31
31
|
if Mongoid.broken_aggregables
|
|
32
32
|
{ "count" => 0, "sum" => nil, "avg" => nil, "min" => nil, "max" => nil }
|
|
@@ -121,7 +121,7 @@ module Mongoid
|
|
|
121
121
|
# @return [ MapReduce ] The map/reduce object.
|
|
122
122
|
def out(location)
|
|
123
123
|
normalized = location.dup
|
|
124
|
-
normalized.
|
|
124
|
+
normalized.transform_values! do |value|
|
|
125
125
|
value.is_a?(::Symbol) ? value.to_s : value
|
|
126
126
|
end
|
|
127
127
|
@map_reduce = @map_reduce.out(normalized)
|
|
@@ -147,7 +147,7 @@ module Mongoid
|
|
|
147
147
|
def raw
|
|
148
148
|
validate_out!
|
|
149
149
|
cmd = command
|
|
150
|
-
opts = { read:
|
|
150
|
+
opts = { read: criteria.options.fetch(:read) } if criteria.options[:read]
|
|
151
151
|
@map_reduce.database.command(cmd, (opts || {}).merge(session: _session)).first
|
|
152
152
|
end
|
|
153
153
|
alias :results :raw
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "mongoid/contextual/aggregable/memory"
|
|
4
4
|
require "mongoid/association/eager_loadable"
|
|
5
|
-
require "mongoid/field_readable"
|
|
6
5
|
|
|
7
6
|
module Mongoid
|
|
8
7
|
module Contextual
|
|
@@ -12,7 +11,6 @@ module Mongoid
|
|
|
12
11
|
include Association::EagerLoadable
|
|
13
12
|
include Queryable
|
|
14
13
|
include Positional
|
|
15
|
-
include FieldReadable
|
|
16
14
|
|
|
17
15
|
# @attribute [r] root The root document.
|
|
18
16
|
# @attribute [r] path The atomic path.
|
|
@@ -76,12 +74,12 @@ module Mongoid
|
|
|
76
74
|
# @example Get the distinct values.
|
|
77
75
|
# context.distinct(:name)
|
|
78
76
|
#
|
|
79
|
-
# @param [ String
|
|
77
|
+
# @param [ String | Symbol ] field The name of the field.
|
|
80
78
|
#
|
|
81
79
|
# @return [ Array<Object> ] The distinct values for the field.
|
|
82
80
|
def distinct(field)
|
|
83
81
|
if Mongoid.legacy_pluck_distinct
|
|
84
|
-
documents.map
|
|
82
|
+
documents.map{ |doc| doc.send(field) }.uniq
|
|
85
83
|
else
|
|
86
84
|
pluck(field).uniq
|
|
87
85
|
end
|
|
@@ -114,7 +112,7 @@ module Mongoid
|
|
|
114
112
|
#
|
|
115
113
|
# @return [ true, false ] If the count is more than zero.
|
|
116
114
|
def exists?
|
|
117
|
-
|
|
115
|
+
any?
|
|
118
116
|
end
|
|
119
117
|
|
|
120
118
|
# Get the first document in the database for the criteria's selector.
|
|
@@ -122,15 +120,14 @@ module Mongoid
|
|
|
122
120
|
# @example Get the first document.
|
|
123
121
|
# context.first
|
|
124
122
|
#
|
|
125
|
-
# @param [ Integer
|
|
126
|
-
# return, or a hash of options.
|
|
123
|
+
# @param [ Integer ] limit The number of documents to return.
|
|
127
124
|
#
|
|
128
125
|
# @return [ Document ] The first document.
|
|
129
|
-
def first(
|
|
130
|
-
if
|
|
131
|
-
eager_load(
|
|
126
|
+
def first(limit = nil)
|
|
127
|
+
if limit
|
|
128
|
+
eager_load(documents.first(limit))
|
|
132
129
|
else
|
|
133
|
-
eager_load(documents.first
|
|
130
|
+
eager_load([documents.first]).first
|
|
134
131
|
end
|
|
135
132
|
end
|
|
136
133
|
alias :one :first
|
|
@@ -144,20 +141,10 @@ module Mongoid
|
|
|
144
141
|
# @param [ Criteria ] criteria The criteria.
|
|
145
142
|
def initialize(criteria)
|
|
146
143
|
@criteria, @klass = criteria, criteria.klass
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# the middle of that would leave a half-built client behind.
|
|
152
|
-
if (first = criteria.documents.first)
|
|
153
|
-
@root = first._root
|
|
154
|
-
@collection = @root.collection
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# One regexp budget covers the whole scan, so that the limit bounds the
|
|
158
|
-
# query rather than each document individually.
|
|
159
|
-
@documents = Matcher::RegexpBudget.open(criteria.selector) do
|
|
160
|
-
criteria.documents.select { |doc| doc._matches?(criteria.selector) }
|
|
144
|
+
@documents = criteria.documents.select do |doc|
|
|
145
|
+
@root ||= doc._root
|
|
146
|
+
@collection ||= root.collection
|
|
147
|
+
doc._matches?(criteria.selector)
|
|
161
148
|
end
|
|
162
149
|
apply_sorting
|
|
163
150
|
apply_options
|
|
@@ -182,18 +169,14 @@ module Mongoid
|
|
|
182
169
|
# @example Get the last document.
|
|
183
170
|
# context.last
|
|
184
171
|
#
|
|
185
|
-
# @param [ Integer
|
|
186
|
-
# return, or a hash of options.
|
|
187
|
-
#
|
|
188
|
-
# @option limit_or_opts [ :none ] :id_sort This option is deprecated.
|
|
189
|
-
# Don't apply a sort on _id if no other sort is defined on the criteria.
|
|
172
|
+
# @param [ Integer ] limit The number of documents to return.
|
|
190
173
|
#
|
|
191
174
|
# @return [ Document ] The last document.
|
|
192
|
-
def last(
|
|
193
|
-
if
|
|
194
|
-
eager_load(
|
|
175
|
+
def last(limit = nil)
|
|
176
|
+
if limit
|
|
177
|
+
eager_load(documents.last(limit))
|
|
195
178
|
else
|
|
196
|
-
eager_load(documents.last
|
|
179
|
+
eager_load([documents.last]).first
|
|
197
180
|
end
|
|
198
181
|
end
|
|
199
182
|
|
|
@@ -248,28 +231,44 @@ module Mongoid
|
|
|
248
231
|
#
|
|
249
232
|
# @param [ Integer ] value The number of documents to return.
|
|
250
233
|
#
|
|
251
|
-
# @return [
|
|
234
|
+
# @return [ Memory ] The context.
|
|
252
235
|
def limit(value)
|
|
253
236
|
self.limiting = value
|
|
254
237
|
self
|
|
255
238
|
end
|
|
256
239
|
|
|
240
|
+
# Pluck the field values in memory.
|
|
241
|
+
#
|
|
242
|
+
# @example Get the values in memory.
|
|
243
|
+
# context.pluck(:name)
|
|
244
|
+
#
|
|
245
|
+
# @param [ String | Symbol ] *fields Field(s) to pluck.
|
|
246
|
+
#
|
|
247
|
+
# @return [ Array ] The array of plucked values.
|
|
257
248
|
def pluck(*fields)
|
|
258
249
|
if Mongoid.legacy_pluck_distinct
|
|
259
250
|
documents.pluck(*fields)
|
|
260
251
|
else
|
|
261
|
-
documents.map do |
|
|
262
|
-
|
|
263
|
-
retrieve_value_at_path(d, fields.first)
|
|
264
|
-
else
|
|
265
|
-
fields.map do |field|
|
|
266
|
-
retrieve_value_at_path(d, field)
|
|
267
|
-
end
|
|
268
|
-
end
|
|
252
|
+
documents.map do |doc|
|
|
253
|
+
pluck_from_doc(doc, *fields)
|
|
269
254
|
end
|
|
270
255
|
end
|
|
271
256
|
end
|
|
272
257
|
|
|
258
|
+
# Pick the field values in memory.
|
|
259
|
+
#
|
|
260
|
+
# @example Get the values in memory.
|
|
261
|
+
# context.pick(:name)
|
|
262
|
+
#
|
|
263
|
+
# @param [ String | Symbol ] *fields Field(s) to pick.
|
|
264
|
+
#
|
|
265
|
+
# @return [ Object, Array<Object> ] The picked values.
|
|
266
|
+
def pick(*fields)
|
|
267
|
+
if doc = documents.first
|
|
268
|
+
pluck_from_doc(doc, *fields)
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
273
272
|
# Tally the field values in memory.
|
|
274
273
|
#
|
|
275
274
|
# @example Get the counts of values in memory.
|
|
@@ -293,7 +292,7 @@ module Mongoid
|
|
|
293
292
|
#
|
|
294
293
|
# @param [ Integer ] value The number of documents to skip.
|
|
295
294
|
#
|
|
296
|
-
# @return [
|
|
295
|
+
# @return [ Memory ] The context.
|
|
297
296
|
def skip(value)
|
|
298
297
|
self.skipping = value
|
|
299
298
|
self
|
|
@@ -307,7 +306,7 @@ module Mongoid
|
|
|
307
306
|
# @param [ Hash ] values The sorting values as field/direction(1/-1)
|
|
308
307
|
# pairs.
|
|
309
308
|
#
|
|
310
|
-
# @return [
|
|
309
|
+
# @return [ Memory ] The context.
|
|
311
310
|
def sort(values)
|
|
312
311
|
in_place_sort(values) and self
|
|
313
312
|
end
|
|
@@ -535,10 +534,11 @@ module Mongoid
|
|
|
535
534
|
# _translations hash so that we can get the specified translation in
|
|
536
535
|
# the remaining
|
|
537
536
|
if field&.localized?
|
|
538
|
-
document.
|
|
537
|
+
document.send("#{segment}_translations")
|
|
539
538
|
end
|
|
540
539
|
end
|
|
541
|
-
|
|
540
|
+
meth = klass.aliased_associations[segment] || segment
|
|
541
|
+
res.nil? ? document.try(meth) : res
|
|
542
542
|
elsif document.is_a?(Hash)
|
|
543
543
|
# TODO: Remove the indifferent access when implementing MONGOID-5410.
|
|
544
544
|
document.key?(segment.to_s) ?
|
|
@@ -557,6 +557,22 @@ module Mongoid
|
|
|
557
557
|
retrieve_value_at_path(curr, remaining)
|
|
558
558
|
end
|
|
559
559
|
end
|
|
560
|
+
|
|
561
|
+
# Pluck the field values from the given document.
|
|
562
|
+
#
|
|
563
|
+
# @param [ Document ] doc The document to pluck from.
|
|
564
|
+
# @param [ String | Symbol ] *fields Field(s) to pluck.
|
|
565
|
+
#
|
|
566
|
+
# @return [ Object, Array<Object> ] The plucked values.
|
|
567
|
+
def pluck_from_doc(doc, *fields)
|
|
568
|
+
if fields.length == 1
|
|
569
|
+
retrieve_value_at_path(doc, fields.first)
|
|
570
|
+
else
|
|
571
|
+
fields.map do |field|
|
|
572
|
+
retrieve_value_at_path(doc, field)
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
end
|
|
560
576
|
end
|
|
561
577
|
end
|
|
562
578
|
end
|