Skip to content

Instantly share code, notes, and snippets.

@zignd
Forked from tamoyal/gist:10441108
Last active March 23, 2016 15:18
Show Gist options
  • Select an option

  • Save zignd/b0ba8656c3dd69cb580d to your computer and use it in GitHub Desktop.

Select an option

Save zignd/b0ba8656c3dd69cb580d to your computer and use it in GitHub Desktop.
Configuring some basic users on MongoDB
# Start the MongoDB server
C:\> mongod
# Start a MongoDB client and create a new admin user
C:\> mongo
> use admin
> db.createUser({ user: "admin", pwd: "123456", roles: [{ role: "root", db: "admin" }]})
# Create a new user for a database of your choice
> use testdb
> db.createUser(
{
user: "testuser",
pwd: "123456",
roles: ["readWrite"]
}
)
> exit
# Now whenever you start the server start it with
C:> mongod --auth
# So clients will be forced to authenticate like
C:> mongo -u "testuser" -p "123456" --authenticationDatabase testdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment