Get the App
SLTechnology News&Howtos  ›  Database  › 

User management

Shulou Source: shulou.com Published: 2022-06-01 21:59:44 10月21日 Update

User Management of mongodb

Note:

A) in mongodb, there is an admin database, which involves server configuration operations, so you need to switch to admin data first.

That is, use admin,-- > is equivalent to entering superuser management mode.

B) mongo users are built on a database basis, and each database has its own administrator.

C) when we set up users, we need to first set up an administrator under the admin database-after this administrator logs in, it is equivalent to a super administrator.

0: view users

1: add user

Command: db.addUser ()

Simple parameter: db.addUser (username, password, read-only)

Note: after adding users, we log out and log in again and find that we can still read the database directly.

Reason: when the mongodb server starts, authentication is not required by default.

For the user to take effect, specify the-- auth option when you need to start the server.

In this way, authentication is needed when operating.

Then it will be restricted:

Enter the account password to pass the verification:

Example:

1: add user

Use admin

Db.addUser ('sa','sa',false)

2: authentication

Use test

Db.auth (username, password)

3: change the user's password

Use test

Db.changeUserPassword (user name, new password)

4: delete the user

Use test

Db.removeUser (user name)

Note: if you need to add more permissions to the user, you can use the json structure to pass the user parameters

Example:

Use test

Db.addUser ({user:'guan',pwd:'111111',roles: ['readWrite,dbAdmin']})

Tags: User administration data database password user name administrator server service authentication parameter login next again unit reason command level more permissions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Linux Shulou Tech Info Docker