9

My mongo version : 2.6.11
I want to check db.serverStatus() in my robomomgo
But got errmsg:

{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { serverStatus:   1.0 }",
    "code" : 13
}

How can I add authorization ??

I find a command can create user with authorization :

db.createUser(
    {
      user: "tester",
      pwd: "password",
      roles: [             
         { role: "readWrite", db: "test" }
      ]
    }
);

But I don't know which is db.serverStatus() 's database name??
How can I authorize it??

1 Answer 1

16

You need to grant the clusterMonitor role to the user running the db.serverStatus command. You can grant this role to a user by calling the `grantRolestoUser.

Here's a list of other clusterMonitor roles

use admin

db.createUser(
    {
      user: "clustermonitor",
      pwd: "password",
      roles: [             
         { role: "readWrite", db: "admin" }
      ]
    }
);

db.grantRolesToUser(
  "clusterMonitor",
   [
     { role: "clusterMonitor", db:"admin"} 
   ]
);
2
  • Two notes: This can be done in one command by adding the clusterMonitor role to the roles array in the createUser statement. And, of course, one has to authenticate against the admin database. Nov 24, 2015 at 7:23
  • Opps, the createUser and grantRolesToUser work on two distinct users, i.e. "clustermonitor" != "clusterMonitor.
    – Ben Hyde
    Dec 31, 2020 at 15:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.