Skip to content

Instantly share code, notes, and snippets.

@cppshane
Created May 15, 2022 20:02
Show Gist options
  • Save cppshane/12596c9921f73f8ccd468d2a6cb5067a to your computer and use it in GitHub Desktop.
Save cppshane/12596c9921f73f8ccd468d2a6cb5067a to your computer and use it in GitHub Desktop.
Mongo Initial Permissions
# Why does initial setup of Mongo always give me permission issues?
mongosh
use admin
db.createUser(
{
user: "adminUser",
pwd: passwordPrompt(),
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
}
)
use example_database
db.createUser(
{
user: "shane",
pwd: passwordPrompt(),
roles: [
{ role: "readWrite", db: "example_database" }
]
}
)
# set the following in /etc/mongo.conf
# security:
# authorization: enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment