简体   繁体   English

Mongodb Node JS serverStatus 总是返回false

[英]Mongodb Node JS serverStatus always returns false

I'm new to mongo and am messing around with the admin serverStatus.我是 mongo 的新手,正在处理管理 serverStatus。 For me, it always returns false when I am expecting an object.对我来说,当我期待一个对象时,它总是返回 false。 I'm running mongod with auth enabled.我在启用身份验证的情况下运行 mongod。 Are there specific user privs that are required?是否需要特定的用户权限? I can't find much documentation other than what is supplied by the API docs from the nodejs drivers or the mongodb manual.除了来自 nodejs 驱动程序或 mongodb 手册的 API 文档提供的内容之外,我找不到太多文档。

MonogDB 3.4 NodeJS drivers 2.2 MonogDB 3.4 NodeJS 驱动程序 2.2

var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://user:pass@localhost:27017/test?authMechanism=DEFAULT&authSource=test', function(err, db) {
  var adminDB = db.admin();
  adminDB.serverStatus(function(err, status) {
    console.log(status);
    db.close();
  });
});

Thanks!谢谢!

I found the answer.我找到了答案。 With auth enabled databases you need to grant a role to the executing user with the serverStatus action.对于启用身份验证的数据库,您需要使用 serverStatus 操作向执行用户授予角色。

db.createRole(
   {
     role: "mongostatRole",
     privileges: [
       { resource: { cluster: true }, actions: [ "serverStatus" ] }
     ],
     roles: []
   }
)

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

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