MongoDB聚合,有没有一种方法可以从聚合游标中获取executionStats? [英] MongoDB Aggregation, is there a way to get executionStats from an aggregate cursor?

查看:228
本文介绍了MongoDB聚合,有没有一种方法可以从聚合游标中获取executionStats?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MongoDB 3.0.4,并且我有一个数据库,其中包含要汇总的数据.问题是,它花费的时间比应该的要长.我做了我的作业(至少我想至少是这样),我看到了函数explain()以及关于聚合和索引优化的许多技巧,但即使如此,我仍然对此表示怀疑.

I am using MongoDB 3.0.4 and i have a database with data which i want to aggregate. The problem, it takes wayyyyy longer than it should. I did my homework (at least to a minimum i guess), i saw the function explain() and lots of tips about aggregation and indexes optimization but even so, i'm still doubtful.

最让我烦恼的是,我无法在聚合游标上正确使用explain()函数.当然,您可以直接将选项传递给聚合函数,但不允许您更改详细程度.

What annoys me the most is that i can't use the explain() function properly on aggregate cursor. There is of course the option you can pass directly to the aggregate function but it does not allow you to change the verbosity.

我可以使用find().explain("executionStats").有用.我还使用了该选项来强制聚合返回游标.但是我什么也做不了:

I can use find().explain("executionStats"). It works. I also used the option to force the aggregate to return a cursor. Yet i couldn't do anything in the form of :

db.coll.aggregate( ... { cursor : { batchSize : 0}}).explain("executionStats")

var a = db.coll.aggregate( ... { cursor : { batchSize : 0}}) a.explain("executionStats")

var a = db.coll.aggregate( ... { cursor : { batchSize : 0}}) a.explain("executionStats")

另一方面:

db.coll.explain("executionStats").aggregate( ... )

可以工作,但是使用的详细程度级别错误,我无法获得我想要的信息...

works but uses the wrong level of verbosity and i can't get the informations i want...

因此,实际的查询是:

`
db.pmsi.aggregate([
{ $match : { $GHM_Obtenu : { $in : ["040M51", "04M052"] } } },
{ $project : { "_id" : 0, "$GHM_Obtenu" : 1 } },
{ $group : {
    _id : { "$GHM_Obtenu" },
    count : { $sum : 1 } }
}
],{
    cursor : { batchSize : 0 }
})`

想知道的人在"GHM_Obtenu"字段上有一个索引.

There is an index on the field "GHM_Obtenu" for those who wonder.

无论如何,问题仍然存在: 有没有一种方法可以从聚合请求中获取executionStats?

Anyway, the question remains : Is there a way to get the executionStats from an aggregate request ?

感谢您抽出宝贵的时间阅读我的问题,希望我不会错过任何显而易见的事情.

I thank you for taking the time to read my question and i hope i didn't missed something too obvious.

干杯!

推荐答案

来自mongodb

From mongodb documentation, you can run an {explain: true} as option for aggregation.

db.collection.aggregate(pipeline, options)¶

这篇关于MongoDB聚合,有没有一种方法可以从聚合游标中获取executionStats?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆