Created
December 21, 2016 06:11
-
-
Save RICH0423/145ee08f4bfbf124af862bdbc5746528 to your computer and use it in GitHub Desktop.
MongoDB create user
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
| use admin | |
| db.createUser( | |
| { | |
| user: "admin", | |
| pwd: "pass", | |
| roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] | |
| } | |
| ) | |
| use anotherDB | |
| db.createUser( | |
| { | |
| user: "api", | |
| pwd: "apipass", | |
| roles: [ { role: "readWrite", db: "anotherDB" }, | |
| { role: "readWrite", db: "anotherDB2" } ] | |
| } | |
| ) | |
| // login with user info. | |
| mongo --host <ip> --port 27017 -u <username> -p <password> --authenticationDatabase <dbname> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment