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

_matches?() returns incorrect values for numeric selectors and arrays containing hashes

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 6.4.5, 7.1.2
    • Component/s: None
    • None

      https://github.com/mongodb/mongoid/pull/4382 from 2017 added support to _matches?() for keys specifying the index of an array, but

      _matches?() gives incorrect results when an array contains hash objects

       

      document: {"occupants" => [{"name" => "Tim"},{"name" => "Logan"}]}
      
      selector: {"occupants.2" => {"$exists" => true}
      document._matches?(selector) # returns true, but should be false
      
      selector: {"occupants.non_numeric_key" => {"$exists" => true}
      document._matches?(selector) # returns true, but should be false

       

      The master branch already has tests and works correctly for these cases,

      but 6.4 and 7.1 exhibit the problem.

      https://github.com/mongodb/mongoid/compare/6.4.0-stable...jasonpenny:matches-array-with-hashes-6.4.0 and https://github.com/mongodb/mongoid/compare/7.1-stable...jasonpenny:matches-array-with-hashes-7.1 are a potential fix

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            jasonpenny4@gmail.com Jason Penny
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: