Basic authentication for MongoDB account password mode

Source: Internet
Author: User
Tags connect to mongodb server mongodb connection string mongodb server

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?

    1. 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

    2. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.