如何在node-mongodb-native中启用分析? [英] How do I enable profiling in node-mongodb-native?

查看:87
本文介绍了如何在node-mongodb-native中启用分析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过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中启用分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆