-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Query
-
None
Currently neither `and` nor `or` operations are correctly supported by Mongoid:
irb(main):008:0> Band.where(x:2).and(Band.where(x:3)) MONGODB | localhost:27741 | mongoid.find | STARTED | {"find"=>"bands", "filter"=>{"x"=>3}, "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x0000563714d4f070 @seconds=1548439192, @increment=1>, "signature"=>{"hash"=><BSON::Binary:0x47397286344620 type=generic data=0x0000000000000000...>, "keyId"=>0}},... MONGODB | localhost:27741 | mongoid.find | SUCCEEDED | 0.001s => #<Mongoid::Criteria selector: {"x"=>2} options: {} class: Band embedded: false> irb(main):009:0> Band.where(x:2).or(Band.where(y:3)) MONGODB | localhost:27741 | mongoid.find | STARTED | {"find"=>"bands", "filter"=>{"y"=>3}, "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x0000563714d93630 @seconds=1548439212, @increment=1>, "signature"=>{"hash"=><BSON::Binary:0x47397286484620 type=generic data=0x0000000000000000...>, "keyId"=>0}},... MONGODB | localhost:27741 | mongoid.find | SUCCEEDED | 0.001s => #<Mongoid::Criteria selector: {"x"=>2} options: {} class: Band embedded: false>
What should happen: https://guides.rubyonrails.org/active_record_querying.html#or-conditions
Specifying the same field multiple times overwrites previous specifications:
irb(main):010:0> Band.where(x:2).where(y:4) => #<Mongoid::Criteria selector: {"x"=>2, "y"=>4} options: {} class: Band embedded: false> irb(main):011:0> Band.where(x:2).where(x:4) => #<Mongoid::Criteria selector: {"x"=>4} options: {} class: Band embedded: false>
Rails master has `and`, `or` and `not` implemented.
- causes
-
MONGOID-5033 Cannot use any_of with multiple conditions when using symbol operators on Time fields and passing Date instances
- Closed
- is duplicated by
-
MONGOID-4714 Criteria#not ignores all but first argument
- Closed
- is related to
-
MONGOID-4807 Make $all combinations in Criteria behave like other logical combinations
- Closed
-
MONGOID-4808 Require that Criteria strategies are explicitly requested, use $and behavior by default for all/in/nin
- Closed
-
MONGOID-4806 Produce the same query shapes with Criteria#where and Criteria#and
- Closed
-
MONGOID-4855 Document any_of
- Closed
- links to