Playing around with mongodb

Posted: March 25th, 2011 | Author: | Filed under: mongodb | 1 Comment »

In my first post on this blog, I set a goal of filling the holes in my tech education. Goals 4 and 5 were to play around mapreduce/hadoop for large scale data processing and gain MySQL knowledge. I decided to squish them both into one and try out mongodb, which is deployed at companies like shutterfly, foursquare, intuit, and others.

So lets start from scratch. Download the correct distribution here and untar it (your version number may be different):

curl http://downloads.mongodb.org/osx/mongodb-osx-x86_64-1.8.0.tgz > mongo.tgz
tar xzf mongo.tgz

Now make a directory for the data, open a new terminal window in the same working directory, and start mongodb:

mkdir -p /data/db
./mongodb-osx-x86_64-1.8.0/bin/mongod

If you see: Error: couldn’t connect to server 127.0.0.1 shell/mongo.js:79 its because you did ./mongodb-osx-x86_64-1.8.0/bin/mongo, which connects to an existing database, rather than ./mongodb-osx-x86_64-1.8.0/bin/mongod, which initializes one.

In your other open terminal do:

./mongodb-osx-x86_64-1.8.0/bin/mongod

then you are good to start creating entries and querying.

db.foo.save( { a : 1 } )
db.foo.find()

Thats it. Also, here is a handy MySQL to mongodb conversion chart. I’m going to work on a fun and quasi-advanced stat function, but I’ll write that up in a separate post.


One Comment on “Playing around with mongodb”

  1. 1 David said at 10:53 pm on March 25th, 2011:

    Inspiring! Downloading now as I write this.


Leave a Reply