Skip to content

Instantly share code, notes, and snippets.

@RICH0423
Created December 21, 2016 06:11
Show Gist options
  • Select an option

  • Save RICH0423/145ee08f4bfbf124af862bdbc5746528 to your computer and use it in GitHub Desktop.

Select an option

Save RICH0423/145ee08f4bfbf124af862bdbc5746528 to your computer and use it in GitHub Desktop.
MongoDB create user
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