mongodb 在 Mongo 中测量查询时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36648625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:43:24  来源:igfitidea点击:

Measure time of query in Mongo

mongodbtimesql-execution-plan

提问by Алиса Метелева

How can I measure execution time of query in MongoDB ? I found Mongo-hacker plugin but it looks like it measure time of query including time of displaying all results. In PostgreSQL I use Explain Analyze SELECT ... , but i didn't found any information about time in mongo's db.collection.find({smth}).explain()

如何测量 MongoDB 中查询的执行时间?我找到了 Mongo-hacker 插件,但它看起来像是测量查询时间,包括显示所有结果的时间。在 PostgreSQL 中,我使用 Explain Analyze SELECT ... ,但我没有在 mongo 的 db.collection.find({smth}).explain() 中找到任何有关时间的信息

采纳答案by James Crosswell

The easiest way is to set the profiling level in MongoDB: https://docs.mongodb.org/manual/tutorial/manage-the-database-profiler/

最简单的方法是在 MongoDB 中设置分析级别:https: //docs.mongodb.org/manual/tutorial/manage-the-database-profiler/

Once you've done this, details on all of your queries will be logged to the system profile table.

完成此操作后,所有查询的详细信息都将记录到系统配置文件表中。

回答by Rohit Patwa

You can add .explain("executionStats")at the end of the query.

您可以.explain("executionStats")在查询的末尾添加。