To add roles to a user, use this command:
db.grantRolesToUser( "<username>", [ <roles> ], { <writeConcern> } )
use products
db.grantRolesToUser(
"accountUser01",
[ "readWrite" , { role: "read", db: "stock" } ],
{ w: "majority" , wtimeout: 4000 }
)
To remove roles from a user, use this command:
db.revokeRolesFromUser( "<username>", [ <roles> ], { <writeConcern> } )
use products
db.revokeRolesFromUser( "accountUser01",
[ { role: "read", db: "stock" }, "readWrite" ],
{ w: "majority" }
)
db.getUsers()
db.getUser(<username>)
db.createUser({user: 'steve', pwd: 'secret', roles: [{role: 'root', db: 'admin'}]})
db.auth(<username>, <password>)