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

Criteria for a field clobbered instead of combined when using symbol operators

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.2
    • Affects Version/s: 7.1.1, 7.0.7
    • Component/s: Query
    • None
    • Environment:
      tested on ruby 2.6.6

      When querying using or(), '$or', or even other nested queries like '$and', mongoid is improperly clobbering multiple criteria for the same field.

      For example, `where(:left.gte => 8, :left.lte => 12)` results in the criteria `{"left"=>{"$gte"=>8, "$lte"=>12}}`.

      In contast, using the same as part of or(), `or({:left.gte => 8, :left.lte => 12})` results in the criteria `{"$or"=>[{"left"=>{"$lte"=>12}}]}` which is missing the `:left >= 8` condition entirely.

      Directly specifying '$or' inside of where() exhibits the same problem, as does even using '$and', suggesting that it's farther reaching than merely 'or'.

      An example to reproduce the issue is attached.

        1. test_or_criteria.rb
          2 kB
          thomas morgan

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

              Created:
              Updated:
              Resolved: