Default location: C:\Program Files\MongoDB\Server\4.0\bin
mongo
use admin
db.createUser(
{
user: "your-user",
pwd: "your-password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
exit
Default location: C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
. . .
security:
authorization: "enabled"
. . .
Restart mongodb service
use myDatabase
db.createUser(
{
user: "myUser",
pwd: "xyz123",
roles: [
{ role: "readWrite", db: "myDatabase" }
]
}
)