-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 5.0.0, 5.2.0
-
Component/s: None
-
Environment:Ubuntu Linux 16.04, Ruby 2.3, Rails 4.2, MongoDB 3.2
I know I am a little late, but have only recently upgraded to Mongo 3.2 and mongoid 5. My users reported that one of search queries takes a lot of time.
The query is on Array field which is filed with strings and indexed.
field :search_a, type: Array
index search_a: 1
Collection holds about 200000 documents and search_a field is filed with words splited from name field. Query line is:
self.where(search_a: /^#
/, active: true)
I first thought that the problem is MongoDB but when I tryed with mongoid 4.0.2 the problem was gone. Here is debug from rails console:
-----------------------------------------------------
Mongoid 4.0.2
Parameters:
{"search"=>"avtomobil"}MOPED: 192.168.2.79:27017 COMMAND database=portal_development command={:count=>"reg_registers", :query=>{"search_a"=>/^avtomobil/, "active"=>true}} runtime: 3.8295ms
MOPED: 192.168.2.79:27017 QUERY database=portal_development collection=reg_registers selector={"search_a"=>/^avtomobil/, "active"=>true} flags=[] limit=30 skip=0 batch_size=nil fields=nil runtime: 29.1166ms
Mongoid 5.0.0
Parameters: {"search"=>"avtomobil"}
D, 2017-02-17T11:50:25.275855 #2134 DEBUG – : MONGODB | 192.168.2.79:27017 | portal_development.count | STARTED | {"count"=>"reg_registers", "query"=>{"search_a"=>/^avtomobil/, "active"=>true}}
D, 2017-02-17T11:50:27.532941 #2134 DEBUG – : MONGODB | 192.168.2.79:27017 | portal_development.count | SUCCEEDED | 2.256757491s
D, 2017-02-17T11:50:27.534074 #2134 DEBUG – : MONGODB | 192.168.2.79:27017 | portal_development.find | STARTED | {"find"=>"reg_registers", "filter"=>
, "limit"=>30}
Similar Mongoid 5.2.0
-----------------------------------------------
As you can see query time has gone from few miliseconds to couple of seconds.
I could not test last mongoid since it depends on rails 5.
by
TheR