Get the App
SLTechnology News&Howtos  ›  Database  › 

Basic authentication of password mode of Mongodb account

Shulou Source: shulou.com Published: 2022-06-01 22:18:47 09月23日 Update

Background: the original MongoDB does not use the authentication method of account password to log in, but uses the non-authentication method. Now it needs to be configured to log in and use it in the way of account password. The configuration steps are as follows:

I. configure users with general permissions

1. Use MongoBooster to connect to the Server of MongoDB

two。 Execute the following script to create the administrative user's account aa

Use admindb.createUser ({user: "aa", pwd: "aa", roles: [{role: "userAdminAnyDatabase", db: "admin"}]})

3. Start server authentication mode, log in to the MongoDb server, add auth=true to the mongodb.config file, and then restart the MongoDB service

4. Use the account aa to connect to the Server of MongoDb in MongoBooster

5. Execute the following script to create a user dfy with read and write permissions for test

Use testdb.createUser ({user: "dfy", pwd: "dfy", roles: [{role: "readWrite", db: "sc"}]})

User: user name, pwd: password, roles: specify user roles, you can use an empty array to set empty roles for new users; in the roles field, you can specify built-in roles and user-defined roles. The characters in role can be selected:

Built-In Roles (built-in roles):

1. Database user roles: read, readWrite

two。 Database management roles: dbAdmin, dbOwner, userAdmin

3. Cluster management roles: clusterAdmin, clusterManager, clusterMonitor, hostManager

4. Backup and restore roles: backup, restore

5. All database roles: readAnyDatabase, readWriteAnyDatabase,userAdminAnyDatabase, dbAdminAnyDatabase

6. Superuser role: root

7. Internal role: _ _ system

Second, create a super user (not recommended)

1. Use MongoBooster to connect to the Server of MongoDB, and execute the following script to create the superuser CC

Use admindb.createUser ({user: "CC", pwd: "CC", roles: [{role: "root", db: "admin"}]})

two。 You can start the authentication mode of the server by following step 3 of configuring normal permissions users. The account CC has the permission of Super Admin.

3. How to use the newly configured MongoDB account password in Web?

On the connection configuration page of MongoBooster, click the To URI button to get the current connection string. The new connection string contains the account password information.

In Web.config, you can replace the original MongoDB connection string with the current new connection string.

Tags: Roles users accounts configurations passwords authentication permissions services management data databases methods servers scripts logins modes normal steps information backup Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Microsoft macOS Shulou Technology