Garren Smith

Mongoid and Sinatra duet

3 Sep 2010 - Johannesburg

UPDATE: @kgrz has written an updated version to support Mongoid 3.0. You can view it here

I am slowly catching up with all the latest hotness in the opensource world. I currently am interested in nosql, specifically Mongodb. I decided to do a quick demo with it using Sinatra, my favorite web DSL, to see whats involved with installing it and using a ORD with it. I decided to go with Mongoid, MongoMapper is also a very good option if you prefer a more ActiveRecord style.

To set it up is very easy, first I installed mongodb via homebrew brew install mongodb

This installs mongodb and creates a deamon process so that it is running in the background. To test that it is working go to http://localhost:28017. You should see page giving a the general information. We are now up and running

Now to get it working with Mongoid and Sinatra. Create a Gemfile with the following:

Then install the gems: bundle install

Lets create a document: (I’ve created the demo from Mongoid Documentation)]

Now configure Mongoid and run a test route to get it going

We are ready to go! Let me know how it goes.

blog comments powered by Disqus
Fork me on GitHub