Enable authentication
Mongod boot is not enabled by default, you need to specify –auth boot, or set 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: { <any information> }, roles: [ "<role>""<database>""<role>", ... ]}
Writeconcern:
For example {w: "Majority", J:true, wtimeout:5000}
- W Options: Allowable values are 1, 0, values greater than 1, "majority",;
- J option: Ensure that the Mongod instance writes data to the journal (log) on 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 only applies to 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 the system's Superuser (Dbowner, Useradmin, Useradminanydatabase)
- Internal role: __system
Creatuser Example
Create a Super Administrator
useadmindb.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
use"user""accountAdmin01", "pwd""cleartext password", "customData"12345 }, "roles""clusterAdmin""admin" }, "readAnyDatabase""admin" }, "readWrite" ] }, "majority"5000 } )
Login
use collectionNamedb.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)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MongoDB Learning Note 05--User Management