-
Type: Bug
-
Resolution: Gone away
-
Priority: Minor - P4
-
None
-
Affects Version/s: 7.3.0, 7.1.8, 7.2.3
-
Component/s: Query
Given a model with a Time field defined:
class MyModel
include Mongoid::Document
field :a, type: Time
end
When using any_of with multiple arguments, which Mongoid attempts to combine, and when using $exists as a symbol operator on the time field with a boolean value, Mongoid attempts to evolve the boolean value to a time which fails:
pp MyModel.any_of({:a.exists => true}, a: nil) Traceback (most recent call last): 14: from test.rb:34:in `<main>' 13: from /home/w/.rbenv/versions/2.7.2/lib/ruby/2.7.0/forwardable.rb:235:in `any_of' 12: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selectable.rb:714:in `any_of' 11: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selectable.rb:714:in `tap' 10: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selectable.rb:718:in `block in any_of' 9: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:59:in `store' 8: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:101:in `evolve_multi' 7: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:101:in `map' 6: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:102:in `block in evolve_multi' 5: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:102:in `map' 4: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:102:in `each' 3: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:119:in `block (2 levels) in evolve_multi' 2: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/selector.rb:154:in `evolve' 1: from /home/w/.rbenv/versions/2.7.2/lib/ruby/2.7.0/forwardable.rb:235:in `evolve' /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/mongoid-7.3.0/lib/mongoid/criteria/queryable/extensions/time.rb:52:in `evolve': undefined method `__evolve_time__' for true:TrueClass (NoMethodError) Did you mean? __evolve_object_id__
Note that `or` works when used instead of `any_of`:
(byebug) MyModel.or({:a.exists => true},{a:nil}) #<Mongoid::Criteria selector: {"$or"=>[{"a"=>{"$exists"=>true}}, {"a"=>nil}]} options: {} class: MyModel embedded: false>
Note that the various symbol operators have special value conversion logic defined in Criteria::Queryable::Selectable. For example, for $exists:
key :exists, :override, "$exists" do |value| Mongoid::Boolean.evolve(value) end
When Mongoid is combining conditions with operators, it needs to follow the various rules defined in that file for the various operators that are supported (others are $type and the geo ones).
- related to
-
MONGOID-5172 Criteria#any_of with multiple arguments incorrectly adds conditions to existing top-level $or if one is already present
- Closed