通过设置profile来分析哪些操作时慢查询。
注:要操作的数据库记得设置好权限,要有dbAdmin权限才能操作profile, 比如:user game db.createUser({user: “game”, pwd: “123456”, roles: [ “readWrite”, “dbAdmin” ]})
测试环境在mongodb 4, 通过控制台,db.setProfilingLevel不成功,无论是通过mongos还是mongod都不成功,最后只能通过配置文件,–profile=1 --slowms=200,在启动时加载,生效。
测试结果:
不正常的全表扫描
正常的带索引的扫描
参考文章:https://blog.youkuaiyun.com/yisun123456/article/details/78274477
https://blog.youkuaiyun.com/u013451157/article/details/78765784