Wednesday, 17 July 2013

Mongo quick start

So I thought I'd jot down how to get started with MongoDB quickly so I don't have to look it all up again next time I have to install it.

These instructions are for mac, tweak as necessary!

Install it

In a terminal
brew update
brew install mongodb

Start it

Then open a terminal and start it
mongod

Open it

Open another terminal and open a mongo shell
mongo

Query it

You should now be in a mongo shell, to view dbs, collections etc... type
show dbs
use whicheverdbyouwant
db
show collections
To find out where the logs, db and config is type in...
db.getSiblingDB("admin").runCommand({getCmdLineOpts:1})
And for basic query, presuming you have a users collection, count all users starting with S
db.users.find( {"userName": /^S/ } ).count()

Find out more

All the above and much, much more... http://docs.mongodb.org/manual/contents/
 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)