MongoDB security and authentication, MongoDB Security Authentication
1. Databases in each MongoDB instance can have many users. If security check is enabled, only database authenticated users can perform read or write operations.
In the authentication context, MongoDB processes common data as the admin database. Users in the admin database are considered as super users (I .e. administrators ).
After authentication, the administrator can read and write all databases and execute specific management commands, such as listDatabases and shutdown.
You must have at least one administrator account before enabling security check.
2. Create an administrator account in the admin database:
Use admin;
Db. addUser ("root", "root ");
Create a common account in the test database:
Use test;
Db. addUser ("zhangsan", "123 ");
Db. addUser ("lisi", "123", true );
Note: the password of the user zhangsan is 123. It has the read and write permissions on the test database. The password is 123. It has the read-only permission on the test database.
Restart the Database Service and enable the security check: mongod -- dbpath d: \ mongo_data -- auth