Dino Geek, try to help you

How to set authority in MongoDB?


In MongoDB, you can manage roles and users to set authority and control access to the data and services. The permissions are set using the database commands like db.createUser() or db.updateUser().

1. Enable Access Control:

By default, MongoDB doesn’t enable access control, so you have to enable it manually. You can do so by adding –-auth parameter in the MongoDB service file.

1. Create a User Administrator:

Before you can create additional users, you must first create a user administrator. This administrator user is created in the admin database and has privileges to manage user and roles such as creating users, granting and revoking roles from users, and creating and modifying custom roles.

```
use admin
db.createUser( { user: “myUserAdmin”, pwd: “abc123”, // or cleartext password roles: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ] }
)
```

1. Connect to the instance using the user administrator:

```
mongo —port 27017 -u “myUserAdmin” -p “abc123” —authenticationDatabase “admin“
```

1. Create additional users:

For example, to create a user authorized to use the reporting database, you would:

```
use reporting
db.createUser( { user: “reportsUser”, pwd: “123456”, roles: [ { role: “read”, db: “reporting” }, { role: “read”, db: “products” }, { role: “read”, db: “sales” }, { role: “readWrite”, db: “accounts” } ] }
)
```

This provides a way to control what actions users and roles can perform against which databases or even on specific collections or cluster wide operations.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use