首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在mongodb中查找不使用索引或速度较慢的查询

如何在mongodb中查找不使用索引或速度较慢的查询
EN

Stack Overflow用户
提问于 2013-08-27 03:34:28
回答 4查看 41.2K关注 0票数 25

有没有办法在mongodb中找到不使用索引或速度慢的查询?在MySQL中,通过配置文件中的以下设置,这是可能的:

代码语言:javascript
复制
log-queries-not-using-indexes = 1
log_slow_queries = /tmp/slowmysql.log
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-08-27 14:42:44

MongoDB中的等效方法是使用query profiler来跟踪和诊断慢查询。

在为数据库启用性能分析的情况下,较慢的操作将写入system.profile上限集合(默认情况下大小为1Mb )。您可以使用slowms parameter调整慢速操作的阈值(默认为100ms)。

票数 22
EN

Stack Overflow用户

发布于 2013-08-27 03:38:10

您可以使用以下两个mongod选项。第一个选项不使用索引的查询失败(仅限V2.4),第二个选项记录的查询速度慢于某个ms阈值(默认值为100ms)

代码语言:javascript
复制
--notablescan

Forbids operations that require a table scan.

--slowms <value>

Defines the value of “slow,” for the --profile option. The database logs all slow queries to the log, even when the profiler is not turned on. When the database profiler is on, mongod the profiler writes to the system.profile collection. See the profile command for more information on the database profiler.
票数 7
EN

Stack Overflow用户

发布于 2017-04-22 02:37:20

如果有人在这个老问题上从谷歌来到这里,我发现explain确实帮助我解决了我从日志中看到的导致COLLSCAN的特定查询。

示例:

db.collection.find().explain()

这将让您知道查询使用的是COLLSCAN (基本游标)还是index (BTree)等。

https://docs.mongodb.com/manual/reference/method/cursor.explain/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18451681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档