Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4807

Make $all combinations in Criteria behave like other logical combinations

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Currently when $all criteria are combined the parameters are unioned, such that the combination is effectively an OR of the pieces rather than an AND:

      irb(main):007:0> Band.all(foo:[2]).all(foo:[1])
      => #<Mongoid::Criteria
        selector: {"foo"=>{"$all"=>[2, 1]}}
        options:  {}
        class:    Band
        embedded: false>
      
      

      Because of this, all can alter the meaning of existing conditions in the criteria. In the below example where is changed to be respected only some of the time:

      irb(main):016:0> Band.where(foo:3).all(foo:[2])
      => #<Mongoid::Criteria
        selector: {"foo"=>{"$all"=>[3, 2]}}
        options:  {}
        class:    Band
        embedded: false>
      

      Similarly to 4697, both conditions should be added as $all requirements (and the resulting query would be unsatisfiable in these examples).

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: