是否有类似 mongodb 的 sql profiler 这样的等效工具? [英] Is there an equivalent tool like sql profiler for mongodb?
问题描述
我想知道是否有类似 mongodb 的 sql profiler 这样的等效工具.具体来说,我想看看我的代码正在生成和运行哪些 monogdb 查询.
I would like to know if there is an equivelent tool like sql profiler for mongodb. Specifically, I would like to see what monogdb queries are being generated and are being run from my code.
所以,当我有这样的代码时:
So, when I have code such as:
var Logs = MvcApplication.MongoLoggingDatabase.GetCollection<Log>("Log")
.Find(queryDocument)
.Select(x => new LogDto { ModelNumber = x.Request.ModelNumber, Make = x.Request.Make, TimeStamp = x.TimeStamp, UserId = x.UserId })
.OrderByDescending(x => x.TimeStamp)
.Skip(pageSize * (page - 1))
.Take(pageSize);
我想知道正在生成和运行什么实际的 mongodb 查询,以便在查询数据库时帮助优化我的代码.
I would like to know what actual mongodb query is being generated and ran in order to help optimize my code when it queries the database.
推荐答案
MongoDB 包含一个简单的分析器.看这里:http://www.mongodb.org/display/DOCS/Database+Profiler
MongoDB includes a simple profiler. See here: http://www.mongodb.org/display/DOCS/Database+Profiler
如果您将分析级别设置为 2,那么所有查询都将写入system.profiler"集合,以便您查看.如果您将分析级别设置为 1,则只会写入慢查询(默认情况下,这些查询被定义为慢于 100 毫秒的查询,但这是一个可配置的参数).
If you set the profiling level to 2, then all queries will be written to the "system.profiler" collection so you can take a look. If you set the profiling level to 1, then just the slow queries will be written (by default these are defined as queries slower than 100ms, but this a configurable parameter).
对于诊断慢查询,解释"功能也非常有用.看这里http://www.mongodb.org/display/DOCS/Explain
For diagnosing slow queries, the "explain" functionality is also very helpful. See here http://www.mongodb.org/display/DOCS/Explain
如果您知道哪些查询很慢,您可以使用解释来确定数据库正在使用(或未使用)哪个索引.
One you know which queries are slow, you can use explain to figure out which index the database is using (or not using).
这篇关于是否有类似 mongodb 的 sql profiler 这样的等效工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!