我的收藏中有70亿数据。 我的数据模型是:MongoDb增加聚合框架性能
{ “_id”:的ObjectId( “515921e3bbea58d25eb07b22”), “服务器ID”:0, “counterId”:0 “插入”:ISODate(“2013-03-21T00: 26:30Z“), ”counterValue“:0.03256159112788737,”min“:-29.967438408872113, ”max“:20.032561591127887}。
我有2个索引serverId,counterId; 和我的查询是:
{$比赛:{ '插入':{$ GTE:新的日期( “2013-03-21T00:00:00Z”),$ LT: 新的日期(“2013 -03-22T10:00:00Z“)}}},{$ group: {_id:{serverId:'$ serverId',counterId:'$ counterId'},avgValue:{$ avg: '$ counterValue'} }}
查找平均counterValues,按照serverId,counterId分组,插入到特定日期之间。
但它需要13秒,我需要它需要1秒。
我该怎么做?
什么是你的工作集大小vs RAM?如果您想避免完整的收集扫描,您绝对需要为“插入”列编制索引。 – WiredPrairie