Skip to content

Instantly share code, notes, and snippets.

@valentincognito
Last active January 30, 2019 02:15
Show Gist options
  • Save valentincognito/39a27dd6a92d4779b04493d1bafe331c to your computer and use it in GitHub Desktop.
Save valentincognito/39a27dd6a92d4779b04493d1bafe331c to your computer and use it in GitHub Desktop.

Add mongodb to your path

Default location: C:\Program Files\MongoDB\Server\4.0\bin

Create a superadmin

mongo
use admin
db.createUser(
  {
    user: "your-user",
    pwd: "your-password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)
exit

Enable authentication in config file

Default location: C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg

 . . .
security:
  authorization: "enabled"
 . . . 

Restart mongodb service

Create additional users

use myDatabase
db.createUser(
  {
    user: "myUser",
    pwd: "xyz123",
    roles: [ 
      { role: "readWrite", db: "myDatabase" } 
    ]
  }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment