Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 737
evilcelery Avatar asked Jul 18 '26 15:07

evilcelery


1 Answers

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.

like image 148
Adam Comerford Avatar answered Jul 20 '26 19:07

Adam Comerford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!