Csdn's Markdown editor is really bad enough, this article is lost again
Enable authentication
Mongod boot is not enabled by default, you need to specify –auth boot. or set the Security.authorization to "enabled" in the configuration file.
Create user
db.createUser(user, writeConcern)
- Document http://docs.mongodb.org/manual/reference/method/db.createUser/#db. CreateUser
User format
"<name>", "<cleartext password="">", customData: { }, roles: [ "<role>""<database>""<role>", ... ]}
Writeconcern:
For example {w: "Majority", J:true, wtimeout:5000}
W Options: The agreed values are 1, 0, values greater than 1, "majority", "j" option: Ensure that the Mongod instance writes data to the journal (log) on the disk, which ensures that no data is lost outside of the mongd. Set true to enable.
Wtimeout: Specifies a time limit, in milliseconds. The wtimeout is only suitable for w values greater than 1.
Built-in Roles (built-in role):
- Database user role: Read, readWrite;
- Database management roles: DbAdmin, Dbowner, useradmin;
- Cluster Management role: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager;
- Backup recovery role: backups, restore;
- All database roles: Readanydatabase, Readwriteanydatabase, Useradminanydatabase, dbadminanydatabase
- Super User role: Root
There are also several roles that indirectly or directly provide access to system super users (Dbowner, Useradmin, Useradminanydatabase)
- Internal role: __system
Creatuser Sample Example
Create a Super Administrator
db.createUser({ user:"username", pwd:"password", roles:["root"]})
Create AccountAdmin01 users in the products database, with ReadWrite permissions, Clusteradmin and Readanydatabase permissions to the admin database
db.createUser"user""accountAdmin01", "pwd""cleartext password", "customData"12345 }, "roles""clusterAdmin""admin" }, "readAnyDatabase""admin" }, "readWrite" ] }, "majority"5000 } )
Login
db.auth("username",‘password")
View User
show users
Delete User
db.dropUser("username")
change user Password
db.changeUserPassword("username","password")
Update user
db.createUser(user, writeConcern)
MongoDB Learning Note 05--User Management