1. Each database in a MongoDB instance can have many users. If security checks are turned on, only database authenticated users can perform read or write operations.
In the context of authentication, MongoDB will treat the normal data as the admin database. Users in the Admin database are considered superuser (that is, administrators).
After authentication, administrators can read and write all databases and execute specific administrative commands, such as listdatabases and shutdown.
Be sure to have at least one administrator account before you start the security check.
2. Create an administrator account in the Admin database:
Use admin;
Db.adduser ("root", "root");
Create a regular account in the test database:
Use test;
Db.adduser ("Zhangsan", "123");
Db.adduser ("Lisi", "123", true);
Note: User Zhangsan, password is 123, the test database has read and write permissions to the user Lisi, password is 123, the test database has read-only permissions
Restart the database service and turn on security check: Mongod--dbpath d:\mongo_data--auth
MongoDB Security and authentication