Is there an equivalent tool like sql profiler for mongodb?

让人想犯罪 __ 提交于 2019-12-24 10:46:17

问题


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);

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.


回答1:


MongoDB includes a simple profiler. See here: http://www.mongodb.org/display/DOCS/Database+Profiler

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).

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).



来源:https://stackoverflow.com/questions/10707025/is-there-an-equivalent-tool-like-sql-profiler-for-mongodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!