After MongoDB opens the authorization login, the use of commands such as Mongotop and Mongostat requires the appropriate role authorization. You can use an internal role for authorization, or you can customize the rules for authorization. The second, self-built rules are described here.
1. Switch to admin
use admin
2. Create rules
db.createRole({ role: "mongotopRole", privileges: [{ resource: { cluster: true }, actions: [ "serverStatus", "top" ] }], roles: []})
Specific permission requirements can be viewed in the official documentation.
Demo (mongotop):
? Links: https://docs.mongodb.com/manual/reference/program/mongotop/index.html
? There are mentions in required access, including self-built rules, and built-in roles that meet the requirements. For example:
? In order to connect to a Mongod this enforces authorization with the--auth option, you must use the--username and--pass Word options, and the connecting user must have the serverstatus and top privileges.
? The most appropriate built-in role, which has these privileges is clustermonitor.
3. Authorization Role Rules
db.grantRolesToUser(‘cool‘, [{ role: ‘mongotopRole‘, db: ‘admin‘ }])
4. Using the Mongotop command
At this point, the permissions configuration has been completed, the command can be used normally, but some parameters need to be attached, for example:
mongotop -u username -p password --authenticationDatabase=admin
Mongtop configuration is complete, Mongostat also according to the above operation, specific permissions can be directly to the official document search to know.
MongoDB Authorization to use Mongotop