- Check the docs at: http://docs.mongodb.org/manual/tutorial/control-access-to-mongodb-with-authentication/
- Short version here:
-
Start
mongod
(without -auth) -
Start mongo from the cmd-line as
mongo admin
-
Then create the admin user with
db.addUser("<admin-username>", "<admin-password>")
-
The switch the database to
swk
, which is the database for the appuse swk db.addUser("<app-username>", "<app-password>") exit
-
Shutdown
mongod
from themongo
consoleuse admin db.shutdownServer()
-
Start
mongod -auth
-
Edit
start.sh
, replace the values ofMONGO_USER
andMONGO_PASS
with<app-username>
and<app-password>
-
Remember that once authentication is enabled, the db can only be shutdown via:
use admin
db.auth("<admin-username>", "<admin-password>")
db.shutdownServer()
Some hints on database handling with mongo:
- Several statements for easy useage in the mongo command line client
show dbs
- show all availabe databasesuse swk
- use swk databaseshow collections
- show all available collectionsdb.memberstore.find()
- show all entries in the collection 'memberstore'db.dropDatabase()
- drop currently connected database