evilcelery
evilcelery

Reputation: 16149

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

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)

Upvotes: 3

Views: 1529

Answers (1)

Adam Comerford
Adam Comerford

Reputation: 21692

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.

Upvotes: 7

Related Questions