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!
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: []
}
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.