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

Storable#add_field_expression add values with same operator keys using $and when value is a hash with symbol operator key

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 9.0.0, 8.0.6, 8.1.2, 7.5.4
    • Affects Version/s: None
    • Component/s: None
    • None

      The keys of the hash being added are converted to a string but they keys of the corresponding hash in the selector are not converted to a string so they do not match and wrong result is given from Mongoid::Criteria::Queryable::Storable#add_field_expression
      because '$in' != :$in

      Currently using a symbol rather than a string will result in a different output e.g.

      #Strings
      Band.where("foo"=>{'$in' =>["bar"]}).where('foo' => {'$in' => ['zoom']})
      =>  {"foo"=>{'$in'=>["bar"]}, "$and"=>[{"foo"=>{'$in'=>["zoom"]}}]}
      
      #Symbols
      Band.where("foo"=>{:$in=>["bar"]}).where('foo' => {:$in => ['zoom']})
      => {"foo"=>{:$in=>["zoom"]}}
      With this fix we will see the correct output
      
      #Symbols
      Band.where("foo"=>{:$in=>["bar"]}).where('foo' => {:$in => ['zoom']})
      =>  {"foo"=>{:$in=>["bar"]}, "$and"=>[{"foo"=>{:$in=>["zoom"]}}]}
      

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: