Db.createuser (User,writeconcern)
User This document creates identity authentication and access information about users
Writeconcern This document describes a successful report that ensures that MongoDB provides write operations
The user document, which defines the following form of users:
User field, the name of the new user
PWD field, user's password
Cusomdata field, for any content, such as the user's full name can be introduced
Roles field, specifying the user's role, you can use an empty array to set an empty role for the new user
In the Roles field, you can specify built-in roles and user-defined roles
Built-in Roles (built-in role)
1. Database user role: Read, ReadWrite
2. Database Management role: DbAdmin Dbowner useradmin
3. Cluster Management role: Clusteradmin Clustermanager clustermonitor Hostmanager
4. Backup Recovery role: Restore
5. All database roles: Readanydatabase readwriteanydatabase useradminanydatabase
Db.createuser ({"User": "ABCD",
"pwd": "123456",
"CustomData": {"emp": 12343},
roles:[
{role: "Clusteradmin", DB: "Admin"},
{role: "Readanydatabase", DB: "admin"}, "ReadWrite"]})
1. Add Administrator account
Use admin
Db.createuser ({User: "admin", pwd: "123456", roles:["root"]})
Db.createuser ({User: "admin", pwd: "123456", roles:["root"]})
2. View user Information
Db.system.users.find ()
Db.createuser ({User: "admin", pwd: "admin", Roles:[{role: "Useradminanydatabase", DB: "admin"}])
This article is from the "Dbaspace" blog, make sure to keep this source http://dbaspace.blog.51cto.com/6873717/1976804
MongoDB User Rights Chapter