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

Condition lifting breaks with symbol operators on Ruby <= 2.6

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.0
    • Affects Version/s: 7.1.0, 7.1.1, 7.1.2, 7.1.4, 7.1.5
    • Component/s: None
    • Labels:
    • Environment:
      Ruby 2.6 and lower
    • Minor Change

      Given a document named `Foo` with an array field named `bar`, a search like this fails:

      ```
      Foo.and( [ { bar:

      { '$in': ['a', 'b', 'c'] }

      }, { bar:

      { '$in': ['d', 'e', 'f'] }

      } ])
      ```

      With the following error:

      > undefined method `start_with?' for :$in:Symbol

      I believe it is caused by the new eliding logic operator check: https://docs.mongodb.com/mongoid/master/tutorials/mongoid-upgrade/#generated-queries

      The operation that does this should be converting the symbol to a string before performing a `starts_with?` check on it.

      The only workaround is to use the old arrow syntax instead to allow the keys to still be stringified:

      ```
      Foo.and( [ { 'bar' =>

      { '$in' => ['a', 'b', 'c'] }

      }, { 'bar' =>

      { '$in' => ['d', 'e', 'f'] }

      } ])
      ```

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            schuyler@jewlr.com Schuyler Jager
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: