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

$eq or $regex must be used in place of implicit equality based on value type

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 7.3.0
    • Affects Version/s: None
    • Component/s: Query
    • Labels:
      None
    • Fully Compatible

      In 7.3 one of the changes is using $eq instead of implicit equality. This can't actually be done because the two operators are not equivalent, specifically they treat regular expressions differently.

      However, the grouped negation is a good feature, and replacing $ne with nor(and(implicit)) I think is correct.

      serene% mongoid=master rails c
      Loading development environment (Rails 6.0.3.4)
      irb(main):001:0> Band.where(year:2020, :year.gt => 2020)
      => 
      #<Mongoid::Criteria
        selector: {"year"=>{"$eq"=>2020, "$gt"=>2020}}
        options:  {}
        class:    Band
        embedded: false>
      
      irb(main):002:0> Band.where(year: /2020/, :year.gt => 2020)
      => 
      #<Mongoid::Criteria
        selector: {"year"=>{"$eq"=>/2020/, "$gt"=>2020}}
        options:  {}
        class:    Band
        embedded: false>
      
      irb(main):003:0> 
      
      serene% rails c
      Loading development environment (Rails 6.0.3.4)
      irb(main):001:0> Band.where(year: /2020/, :year.gt => 2020)
      => 
      #<Mongoid::Criteria
        selector: {"year"=>/2020/, "$and"=>[{"year"=>{"$gt"=>2020}}]}
        options:  {}
        class:    Band
        embedded: false>
      

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

              Created:
              Updated:
              Resolved: