Skip to content

Instantly share code, notes, and snippets.

@razorcd
Last active June 20, 2018 12:43
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 razorcd/0a320188b1764053200744ef34e3a78c to your computer and use it in GitHub Desktop.
Save razorcd/0a320188b1764053200744ef34e3a78c to your computer and use it in GitHub Desktop.
create user in mongo db
//login as admin using the db where the admin user is defined
mongo --port 27017 -u "admin" -p "admin" --authenticationDatabase "admin"
// or the default:
mongo --port 27017 -u "root" -p "password" --authenticationDatabase "root"
//list all system users:
db.system.users.find()
//to add a new user for a specific DB:
use cm-db
db.createUser({user: "cm-user",pwd: "cm-pass",roles: [{"role" : "dbOwner","db" : "cm-db"}]})
db.getUsers() // should show user
use admin
db.system.users.find() // new user should show here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment