简体   繁体   English

MongoDB查询dbpath值

[英]MongoDB query dbpath value

Is there a way to get the value of dbpath of a running MongoDB instance via query, assuming I am connected as an admin? 假设我以管理员身份连接,是否可以通过查询获取正在运行的MongoDB实例的dbpath的值? Unsurprisingly, it does not appear in the result of db.serverStatus command output. 毫不奇怪,它不会出现在db.serverStatus命令输出的结果中。

After a bit of research, I found that it is actually pretty easy: 经过一些研究,我发现这实际上很简单:

db._adminCommand("getCmdLineOpts")

gives you both argv and the parsed options that differ from the defaults, as far as I can see. 据我所知,它为您提供了argv和与默认选项不同的已解析选项。 You can access the dbpath variable via 您可以通过以下方式访问dbpath变量

db._adminCommand("getCmdLineOpts").parsed.storage.dbPath

regardless of where dbpath is defined if it differs from the defaults for your OS, which you most likely have to hard code according to the documentation of the dbpath config variable . 不管dbpath定义在哪里, 如果它与您的操作系统的默认值不同,则您很可能必须根据dbpath config变量文档对其进行硬编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM