I just implemented auth for mongodb, There is a user ‘admin’ in db ‘admin’ and ‘appadmin’ in db ‘mydb’ all working fine. below are my db auth settings:
use admin
db.auth(‘’, ‘’)
db.getUsers()
[
{
"_id" : "admin.admin",
"user" : "admin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "clusterMonitor",
"db" : "admin"
}
]
}
]
use mydb
db.auth()
db.getUsers()
{
"_id" : "mydb.appadmin",
"user" : "mydb",
"db" : "mydb",
"roles" : [
{
"role" : "readWrite",
"db" : "mydb"
},
{
"role" : "userAdmin",
"db" : "mydb"
}
]
}
].
If I run the following,
mongostat --username=admin --password=mypassword --authenticationDatabase=admin
insert query update delete getmore command flushes mapped vsize res faults qr|qw ar|aw netIn netOut conn time
*0 *0 *0 *0 0 1|0 0 240.0M 678.0M 91.0M 0 0|0 0|0 79b 10k 1 11:49:18
*0 *0 *0 *0 0 1|0 0 240.0M 678.0M 91.0M 0 0|0 0|0 79b 10k 1 11:49:19
*0 *0 *0 *0 0 1|0 0 240.0M 678.0M 91.0M 0 0|0 0|0 79b 10k 1 11:49:20
But when I run
* mongostat --username=appadmin --password=mypassword --authenticationDatabase=mydb
Failed: not authorized on admin to execute command { serverStatus: 1, recordStats: 0 },
So I tried to add role ‘clusterMonitor’ in mydb.
db.updateUser(“appadmin”, {roles: [{role: "readWrite", db: “mydb”}, {role: "userAdmin", db: “mydb”}, {role: "clusterMonitor", db: “mydb”}]})
E QUERY Error: Updating user failed: No role named clusterMonitor@mydb.
What is the best way to do mongostat in a auth enabled mongoldb? Please help me to fix the issue or suggest best auth settings. Note: my mongodb version 3.0.6