Dino Geek, try to help you

How to configure authentication in MongoDB?


To configure authentication in MongoDB, you need to follow these steps:

1. Create the User Administrator:

First, start the mongod without access control. \`\`\`bash mongod —port 27017 —dbpath /data/db1 \`\`\` Then, connect to the instance. \`\`\`bash mongo —port 27017 \`\`\` At the mongo prompt, add the user administrator. \`\`\`bash use admin db.createUser( { user: “myUserAdmin”, pwd: passwordPrompt(), // prompts for the password roles: [ { role: “userAdminAnyDatabase”, db: “admin” }, “readWriteAnyDatabase” ] } ) \`\`\`

1. Enable Access Control:

Restart the MongoDB instance with access control. \`\`\`bash mongod —auth —port 27017 —dbpath /data/db1 \`\`\`

1. Authenticate as the User Administrator:

From a mongo shell prompt, authenticate as the user administrator. \`\`\`bash mongo —port 27017 -u “myUserAdmin” -p “mypassword” —authenticationDatabase “admin“ \`\`\`

1. Create Additional Users:

Once authenticated as the user administrator, you can create additional users. Switch to the database where you want to create the user. For example: \`\`\`bash use test db.createUser( { user: “myTester”, pwd: passwordPrompt(), // prompts for the password roles: [ { role: “readWrite”, db: “test” }, { role: “read”, db: “reporting” } ] } ) \`\`\`

1. Connect and Authenticate as a User:

To authenticate during connection: \`\`\`bash mongo —port 27017 -u “myTester” -p “mypassword” —authenticationDatabase “test“ \`\`\` Or to authenticate after connection: \`\`\`bash use test db.auth(“myTester”, passwordPrompt()) // or cleartext password \`\`\`

By following these steps, you have successfully configured the MongoDB authentication.

Source: https://docs.mongodb.com/manual/tutorial/enable-authentication/


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