问题描述
我想通过node-mongodb-native驱动程序对我的MongoDB数据库之一启用概要分析.
I want to enable profiling on one of my MongoDB databases, via the node-mongodb-native driver.
但是,似乎没有Db.setProfilingLevel()
方法(除了在管理数据库上).
However there doesn't seem to be a Db.setProfilingLevel()
method (apart from on the Admin DB).
我尝试使用db.command({setProfilingLevel: 2})
,但得到no such cmd: setProfilingLevel
.
通过db.setProfilingLevel(2)
推荐答案
我明白了您对这些方法的含义,但是我认为db.command尝试的问题在于您试图将Shell Helper作为命令运行而不是命令本身.实际的命令是这样的格式:
I see what you mean about the methods, but I think the issue with the db.command attempt is that you are trying to run a shell helper as a command rather than the command itself. The actual command is this format:
// get current levels
db.runCommand({ profile : -1 })
// set the level to log slow ops
db.runCommand({ profile : 1 })
// set to log slow ops and change the threshold to 200ms
db.runCommand({ profile : 1, slowms : 200 })
//revert to defaults
db.runCommand({ profile : 0, slowms : 100 })
因此,如果您尝试将相关值传递到应该起作用的db.command中.
So, if you try passing the relevant value into db.command that should work.
这篇关于如何在node-mongodb-native中启用分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!