Transfer from http://www.imooc.com/article/18439
First, start MongoDB in a non-authoritative mode.
Non-authorized:
Linux/mac:mongod-f/mongodb/etc/mongo.conf
Windows:mongod--config c:\mongodb\etc\mongo.conf or net start MongoDB (provided MONGO is installed in the service)
Note:
/mongodb/etc/mongo.conf bit MONGO the address where the configuration file resides
Authorized:
Mongod-f/mongodb/etc/mongo.conf--auth
Note:
1.--auth on behalf of authorization to start, need account password to access
2.auth=true can be added to the mongo.conf configuration file for unified management
Two. Create an administrator
1. Start MONGO in a non-authorized manner
2. Create the Admin database
Use admin
3. Add Admin user
Db.createuser ({User: "admin", pwd: "123456", roles:["root"]})
Note: User name and password can be arbitrarily determined
4. Certifications
Db.auth ("admin", "123456")
Three. Start MONGO in an authoritative manner to add users to the database you are using
1. Switching the database
Use test
2. Create a user
Db.createuser ({User: "root", pwd: "123456", roles: [{role: "Dbowner", DB: "Test"}]})
3. Connect the test database via the client
MongoDB creates a user for the database