Mongo: enabling user auth

By default, mongo runs with user auth disabled.

To enable it, do the following:

Create admin user

First, connect to admin database and create "admin" user (it can be named anything, does not necessarily need to be called "admin"):

Enable user auth in mongod.conf and restart mongod

In /etc/mongod.conf, make sure the following is present and restart mongod:

Connect to mongo shell with auth enabled

Create a non-admin user for database access

This one will create "phpunituser" with "readWrite" access to "phpunitdb" database. Make sure "use phpunitdb" is present before db.createUser(...):

Connect to mongo shell as non-admin user