valentincognito
1/30/2019 - 2:15 AM

Authentication

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" } 
    ]
  }
)