Mongodb使用db.shutdownServer()出错

mac2025-08-22  2

 已经完成登录验证 并且成功 但是在使用db.shutdownServer()时 依旧出错

2019-11-01T19:03:42.683+0800 E QUERY [js] Error: shutdownServer failed: { "ok" : 0, "errmsg" : "not authorized on admin to execute command { shutdown: 1.0, lsid: { id: UUID(\"3db00cd6-842b-4c2b-a8e5-d5db6bdf3bc6\") }, $db: \"admin\" }", "code" : 13, "codeName" : "Unauthorized" } :

最后检查发现是缺少hostManger的这个角色,这个角色具有shutdown的权限。

然后将这个角色赋予bjsxt后 就可以继续使用了

db.grantRolesToUser( "bjsxt" , [ { role: "hostManager", db: "admin" } ])

语法:

db.grantRolesToUser( "用户名" , [ { role: "hostManager", db: "admin" } ])

hostManager:提供了监控和管理服务器的权限,包括shutdown节点,logrotate, repairDatabase等。

 

最新回复(0)