Background: The original use of MongoDB does not use the account password authentication method to log in, the use of non-authentication mode; Now it needs to be configured to log in and use as an account password, the configuration steps are as follows:
First, configure normal user rights
1. Connect to the MongoDB server using Mongobooster
2. Execute the following script to create an administrative user's account AA
Use Admindb.createuser ({User: "AA", pwd: "AA", Roles:[{role: "Useradminanydatabase", DB: "Admin"}]})
3. Start the server authentication mode, log in to the MongoDB server, add Auth=true in the Mongodb.config file, and then restart the MongoDB service
4. Use account AA in Mongobooster to connect to MongoDB server
5. Execute the following script to create a user with read and Write permissions for test dfy
Use Testdb.createuser ({User: "Dfy", pwd: "Dfy", Roles:[{role: "ReadWrite", DB: "SC"}]})
User: Username, pwd: password, roles: Specify user roles, you can set empty roles for new users with an empty array, and in the Roles field, you can specify built-in roles and user-defined roles. Roles in role can be selected:
Built-in Roles (built-in role):
1. Database user role: Read, readWrite;
2. Database Management role: DbAdmin, Dbowner, useradmin;
3. Cluster Management role: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager;
4. Backup Restore role: backups, restore;
5. All database roles: Readanydatabase, Readwriteanydatabase,useradminanydatabase, dbadminanydatabase
6. Super User role: Root
7. Internal role: __system
Second, create super User (not recommended)
1. Using Mongobooster to connect to the MongoDB server, execute the next script to create Superuser CC
Use Admindb.createuser ({User: "CC", pwd: "CC", Roles:[{role: "Root", DB: "Admin"}]})
2. Configure the server authentication mode by following step 3 of configuring normal user, account CC has Super Administrator privileges
Third, how to use the new configured MongoDB account password in the Web?
In the Mongobooster Connection Configuration page, click the To URI button, you can see the current connection string, the new connection string contains the account password information
In Web. config, replace the previous MongoDB connection string with the current new connection string.
This article is from the "No Spoiled cat" blog, please be sure to keep this source http://alicedai.blog.51cto.com/5589624/1865121
Basic authentication for MongoDB account password mode