问题
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