-
-
Save zignd/b0ba8656c3dd69cb580d to your computer and use it in GitHub Desktop.
Configuring some basic users on MongoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Start the MongoDB server | |
| C:\> mongod | |
| # Start a MongoDB client and create a new admin user | |
| C:\> mongo | |
| > use admin | |
| > db.createUser({ user: "admin", pwd: "123456", roles: [{ role: "root", db: "admin" }]}) | |
| # Create a new user for a database of your choice | |
| > use testdb | |
| > db.createUser( | |
| { | |
| user: "testuser", | |
| pwd: "123456", | |
| roles: ["readWrite"] | |
| } | |
| ) | |
| > exit | |
| # Now whenever you start the server start it with | |
| C:> mongod --auth | |
| # So clients will be forced to authenticate like | |
| C:> mongo -u "testuser" -p "123456" --authenticationDatabase testdb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment