How do I enable profiling in node-mongodb-native?

廉价感情. 提交于 2019-12-11 03:24:26

问题


I want to enable profiling on one of my MongoDB databases, via the node-mongodb-native driver.

However there doesn't seem to be a Db.setProfilingLevel() method (apart from on the Admin DB).

I've tried using db.command({setProfilingLevel: 2}) but get no such cmd: setProfilingLevel.

Works fine through the mongo shell with db.setProfilingLevel(2)


回答1:


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

So, if you try passing the relevant value into db.command that should work.



来源:https://stackoverflow.com/questions/11861909/how-do-i-enable-profiling-in-node-mongodb-native

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