Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB user Rights Section

Shulou Source: shulou.com Published: 2022-06-01 17:18:47 10月05日 Update

Db.createUser (user,writeConcern)

User this document creates authentication and access information about users

WriteConcern this document describes how to ensure that MongoDB provides a success report for write operations

The user document, which defines the following form of the user:

User field, which is the name of the new user

Pwd field, user's password

CusomData field, which is any content, for example, it can be introduced by the user's full name.

The roles field, which specifies the role of the user. An empty array can be used to set an empty role for new users.

In the roles field, you can specify built-in roles and user-defined roles

Built-In Roles (built-in role)

1. Database user roles: read, readWrite

2. Database management role: dbAdmin dbOwner userAdmin

3. Cluster management role: clusterAdmin clusterManager clusterMonitor hostManager

4. Backup recovery role: backup restore

5. All database roles: readAnyDatabase readWriteAnyDatabase userAdminAnyDatabase

Db.createUser ({"user": "abcd"

"pwd": "123456"

"customData": {"emp": 12343}

Roles: [

{role: "clusterAdmin", db: "admin"}

{role: "readAnyDatabase", db: "admin"}, "readWrite"]})

1. Add an administrator account

Use admin

Db.createUser ({user: "admin", pwd: "123456", roles: ["root"]})

Db.createUser ({user: "admin", pwd: "123456", roles: ["root"]})

2. View user information

Db.system.users.find ()

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

Tags: User role field data database document management information success full name content name backup password form report array administrator account identity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Shulou Tech Info vpn Microsoft