Mongodb: What to know before using?

Wayne Conrad picture Wayne Conrad · Jan 23, 2010 · Viewed 22.8k times · Source

I'm starting a hobby (non-revenue) project using Ruby on Rails. I've done a fair amount of development in Rails using Postgresql, and I can make a pretty good imitation of normalized schema. However, Mongrodb looks shiny and new. What better for trying out something new than a hobby project?

Think back to when you started using Mongodb. What techniques did you learn later that made you say, "If only I knew that when I started!" What plug-ins did you discover that you would have used right from the start, if only you had known? What references would you like to have had bookmarked?

Answer

Emily picture Emily · Jan 26, 2010

I would definitely second the recommendation of MongoMapper if you're going to be using MongoDB with Rails. I will warn you, however, that there is (so far) no documentation other than a couple blog posts. If you're not comfortable digging into the source code to see how things work, it's probably not for you yet.

If you're working outside of Rails, I'd recommend staying away from MongoMapper. Because it's working MongoDB into something similar to what we expect from a SQL-backed ORM, it doesn't really give you a good idea of the power of and of the different thinking behind MongoDB. Spend some time playing around with the lower-level ruby driver, and even in the javascript console.

The other thing I'd recommend, especially since you mentioned knowing how to normalize a schema, is not to think of MongoDB as a database for now. The way you organize your data in MongoDB is very different that with a relational database. Try to think about it more as a place to store and retrieve Ruby hashes. You can do some relational things with MongoDB, but I'd recommend sticking with only self-contained documents while you're trying to wrap your head around NoSQL.

As for what links you should look at, I'd highly recommend reading through everything you can on the MongoDB site. Their documentation is very good. Particularly, take a look at the advanced queries, multikey indexes, and MapReduce to get an idea of some of the unique advantages and strengths of a NoSQL database.