MongoDB version 3.2 (currently up-to-date), the demo is the Linux under the MongoDB authorization authentication
First logon does not start authorization (MONGO default does not start)
./mongod--dbpath=/home/db/data--logpath=/home/db/logs/mongodb.log
Then use the./mongo command to connect to the database
./mongo
Switch to admin database use Admin
Use the Create user command:
Use Admindb.createuser ( { "Coderhuang", "123456", "root", DB: "admin" } ] })
A user named Coderhuang is added to the admin database (Note: MONGO provides a set of user rights for each database)
Then close the database (note: When authorization authentication is initiated, only the root role has permission to shut down the database)
Db.shutdownserver ();
Second logon enables authorization authentication:
./mongod--auth--dbpath=/home/db/data--logpath=/home/db/logs/mongodb.log
Then switch to the Admin database and use the View User command
Use Adminshow Users
The prompt is not authorized
Authorization is required at this time.
Db.auth ("Coderhuang", "123456");
Then you can see the user information by calling the command just now.
Then we need to add the relevant users to our database, where we use db_report as an example
Use db_reportdb.createuser ({ "client", "111111", roles: [ "ReadWrite" , DB: "Db_report" } ]})
This adds a role with read and write permissions to the Db_report database.
To this, MONGO authorized to complete
MongoDB Authorized Login