Skip to content

Instantly share code, notes, and snippets.

@supix
Last active February 18, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supix/c2996d3217ac2e1a3adda7cb71787faa to your computer and use it in GitHub Desktop.
Save supix/c2996d3217ac2e1a3adda7cb71787faa to your computer and use it in GitHub Desktop.
Create read-only, read-write and owner-user users on mongodb database
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