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

Using Regexp query class in mongoid document context fails

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.2.1
    • Component/s: None
    • Labels:
      None

      Hi

      When using Regexp inside a class which includes mongoid::document, its being serializes wrong and produce wrong query.

      reproducing code:

      class SomeObj
        include Mongoid::Document
      
        field :name, type: String
      
        def self.count_obj str
          SomeObj.where(name: Regexp.new("#{str}")).count
        end
      end
      

      mongo logs (not the |name: "#<Mongoid::Matchable::Regexp:0x007fc8536ef348>"|):

      2017-06-20T10:22:20.656+0300 I COMMAND  [conn122] command honeybook-payments-dev.some_objs command: count { count: "some_objs", query: { name: "#<Mongoid::Matchable::Regexp:0x007fc8536ef348>" } } planSummary: EOF keysExamined:0 docsExamined:0 numYields:0 reslen:44 locks:{ Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } } } protocol:op_query 0ms
      

      env:
      rails 4.2.8
      mongo (2.4.1)
      mongoid (5.2.1)
      reproduces on dev machines (osx) and on production (ubuntu 14.04)

      we suspect the new Mongoid::Matchable::Regexp, since if we use ::Regexp in the example above it works

      Thanks

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            boaz@honeybook.com Boaz Adato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: