I have enabled authentication in the MongoDB config file after adding one admin user with the following privileges: userAdmin and userAdminAnyDatabase
This is what worked for me for creating a user prod who connects to database prod assuming I had an admin user (called admin) already in the MongoDB:
> mongo admin --username root --password
> use prod
> db.createUser(
{
user: "prod",
pwd: "",
roles: [ { role: "dbOwner", db: "prod" } ]
}
)
> exit
After this you can login with the new user prod like this:
> mongo prod --username prod --password