2

I'm new to mongo and am messing around with the admin serverStatus. For me, it always returns false when I am expecting an object. I'm running mongod with auth enabled. 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.

MonogDB 3.4 NodeJS drivers 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!

1 Answer 1

2

I found the answer. With auth enabled databases you need to grant a role to the executing user with the serverStatus action.

db.createRole(
   {
     role: "mongostatRole",
     privileges: [
       { resource: { cluster: true }, actions: [ "serverStatus" ] }
     ],
     roles: []
   }
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.