Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongodb user rights

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Mongodb enables user authentication:

After mongodb enables user authentication, log in by user name and password

Now you need to create an account, which requires grant permission, that is, the authorization permission for account management. Note that the account follows the library, so authorization in the specified library must also be verified in the specified library (auth).

Use admin

Switched to db admin

> db.createUser (

... {

... User: "dba11"

... Pwd: "dba11"

... Roles: [{role: "userAdminAnyDatabase", db: "admin"}]

...}

.)

Roles: specify the role of the user, and you can set an empty role for the new user with an empty array; in the roles field, you can specify built-in roles and user-defined roles. The characters in role can be selected:

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

/ / there are also several roles that provide access to the system superuser indirectly or directly (dbOwner, userAdmin, userAdminAnyDatabase)

7. Internal role: _ _ system

Read: allows the user to read the specified database

ReadWrite: allows users to read and write to a specified database

DbAdmin: allows users to perform administrative functions in a specified database, such as index creation, deletion, viewing statistics, or accessing system.profile

UserAdmin: allows users to write to the system.users collection. You can create, delete and manage users in a specified database.

ClusterAdmin: available only in the admin database, giving users administrative rights to all shard and replication set related functions.

ReadAnyDatabase: available only in admin databases, giving users read access to all databases

ReadWriteAnyDatabase: available only in admin databases, giving users read and write permissions to all databases

UserAdminAnyDatabase: available only in admin databases, giving users userAdmin permissions for all databases: the userAdminAnyDatabase role, which is used to manage users, through which users can be created and deleted. Verification: the auth parameter needs to be enabled.

DbAdminAnyDatabase: available only in admin databases, giving users dbAdmin permissions for all databases.

Root: available only in the admin database. Super account, super privilege

-

Show users; views the users under the current library

Because accounts are authorized under the current database that requires authorization, what if they are not in the current database?

> db

Admin

> db.createUser (

... {

... User: "wbx"

... Pwd: "wbx"

... Roles: [

. {role: "readWrite", db: "sss"}, # create accounts for other libraries under the current library, and accounts for test and abc libraries under the admin library

... {role: "readWrite", db: "sssss"}

...]

...}

.)

> show users

How can I check all accounts after creating so many accounts?

Db.system.users.find () .pretty ()

*

Number creation test:

For (var I = 1; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report