db.shutdownServer

Enterprise admin> db.shutdownServer()
MongoServerError[Unauthorized]: not authorized on admin to execute command { shutdown: 1, lsid: { id: UUID(“155e6af9-4094-46c6-b6fd-3694afcaacf5”) }, $db: “admin” }

Enterprise admin> db.getUsers()
{
users: [
{
_id: ‘admin.admin’,
userId: UUID(‘6817e89a-c4de-433c-bb81-f9eaf4b76162’),
user: ‘admin’,
db: ‘admin’,
roles: [
{ role: ‘userAdminAnyDatabase’, db: ‘admin’ },
{ role: ‘dbAdminAnyDatabase’, db: ‘admin’ },
{ role: ‘readWriteAnyDatabase’, db: ‘admin’ }
],
mechanisms: [ ‘SCRAM-SHA-1’, ‘SCRAM-SHA-256’ ]
}
],
ok: 1
}

Why i can not execute this command?

Thanks.
David

Hi @David_Tran,
none of these roles, can perform the shutdown action.
I recommend that you add an appropriate role to perform the shutdown, such as hostManager, as defined in the documentation:

Regards

2 Likes

Thanks for the reply but if i disabled security in the mongod.conf file, it works.

David

Yes, it works. But it also means anyone who connect to your server can do it, anyone who connect to your server can modify and delete all your data.

1 Like

What am i saying if i enabled security in the mongod.conf file, it will not work

@Fabio_Ramohitaj, linked to the documentation that explain what to do to make it work with security.

1 Like

database administrators are not server administrators, and this shutdown operation requires the latter one.

let me give you one needle from the haystack: the page section Fabio linked above gives “hostManager” as an example. check below link and see what other built-in roles you may use, or surf the nearby topics on the left for the permissions you may assign to a custom one.

1 Like