Last active
February 18, 2019 21:37
-
-
Save supix/c2996d3217ac2e1a3adda7cb71787faa to your computer and use it in GitHub Desktop.
Create read-only, read-write and owner-user users on mongodb database
This file contains 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 myDbName | |
// drop users | |
db.dropUser("ro_user"); | |
db.dropUser("rw_user"); | |
db.dropUser("owner_user"); | |
// read-only user | |
db.createUser({ | |
user: "ro_user", | |
pwd: "hereThePassword", | |
roles: [ | |
{ role: "read", db: "myDbName" } | |
], | |
mechanisms:[ | |
"SCRAM-SHA-1" | |
] | |
}); | |
// read-write user | |
db.createUser({ | |
user: "rw_user", | |
pwd: "hereThePassword", | |
roles: [ | |
{ role: "readWrite", db: "myDbName" } | |
], | |
mechanisms:[ | |
"SCRAM-SHA-1" | |
] | |
}); | |
// owner-user | |
db.createUser({ | |
user: "owner_user", | |
pwd: "hereThePassword", | |
roles: [ | |
{ role: "dbOwner", db: "myDbName" } | |
], | |
mechanisms:[ | |
"SCRAM-SHA-1" | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment