MongoDB 3.4如何提高聚合查询速度?

时间:2017-09-21 07:14:32

标签: mongodb

我尝试研究MongoDB 3.4,请告诉我,我有一系列文件:

class A
  attr_reader :body_class
  def initialize
    @body_class = "".extend(Module.new do
      def <<(other)
        return self if self[/\b#{Regexp.escape(other)}\b/]
        concat(' ') unless empty?
        concat(other)
      end
    end)    
  end  
end

我提出要求合并并计算属性数量的请求。 例如,当买家选择过滤器时,这用于互联网商店商品的过滤器:

{"title" : "Televisor № 1", "code" : 1, "attr" : [{"key" : "resolution", "value" : ["1920*1080"]}, {"key" : "network", "value" : ["wi-fi", "lan"]}, {"key" : "diagonal", "value" : ["27"]}]},
{"title" : "Televisor № 2", "code" : 2, "attr" : [{"key" : "resolution", "value" : ["1920*1080"]}, {"key" : "network", "value" : ["wi-fi", "lan"]}, {"key" : "diagonal", "value" : ["27"]}]},
{"title" : "Televisor № 3", "code" : 3, "attr" : [{"key" : "resolution", "value" : ["800*600"]}, {"key" : "network", "value" : ["wi-fi"]}, {"key" : "diagonal", "value" : ["24"]}]},
{"title" : "Televisor № 4", "code" : 4, "attr" : [{"key" : "resolution", "value" : ["800*600"]}, {"key" : "network", "value" : ["wi-fi", "lan"]}, {"key" : "diagonal", "value" : ["24"]}]},
{"title" : "Televisor № 5", "code" : 5, "attr" : [{"key" : "resolution", "value" : ["640*480"]}, {"key" : "network", "value" : ["wi-fi", "lan"]}, {"key" : "diagonal", "value" : ["18"]}]},
{"title" : "Televisor № 6", "code" : 6, "attr" : [{"key" : "resolution", "value" : ["640*480"]}, {"key" : "network", "value" : ["wi-fi", "lan"]}, {"key" : "diagonal", "value" : ["18"]}]},

我收集了50,000台电视机,当我执行查询时(在Robo3T中),它的执行时间是0.5-0.6秒。 在我看来太久了?我可以以某种方式优化它以提高获得结果的速度吗? 我只在'_id'字段上有一个索引

0 个答案:

没有答案