-
Type: Bug
-
Resolution: Works as Designed
-
Priority: 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
- duplicates
-
MONGOID-4429 Unexpected use of Mongoid::Matchable::Regexp in Mongoid::Document classes.
- Closed