Textexpander for short urls Markdown Table of Contents Generator

Setting Up MongoDB with Authentication

16 Apr 2014

I found the various instructions over at MongoDB to be baffling.

Starting from here each page links to 5 other pages that you should read, ad-infinitum, and there seems to be a lot of confusion over the 2.6 instructions and pre-2.6. It all seemed much more complicated than need be.

So here's the short version:

  1. Install MongoDB, I'm not here for that, their instructions are good

  2. Make yourself a config script, here's mine. You'll be able to login and do things even with auth=true because there is not currently an admin user

    400: Invalid request
    

  3. Fire up mongo pointing to that config like so:

    mongod --config /usr/local/etc/mongod.conf &

  4. Now we go in, and create an admin user

    $ mongo

    use admin

    db.createUser({user:'admin',pwd:'adminPassword'})

  5. Authenticate ourselves

    db.auth('admin','adminPassword');

  6. Change to our application database

    use appDatabase

  7. Create our app user

    db.createUser({user:'appUser',pwd:'appPasswrd',roles:['readWrite']})

  8. Log Out of mongo and test the user

    exit

    mongo -u appUser -p appPasswrd appDatabase

That's it, if I'm wrong, or there is another best practice, let me know.