Matthew Stopa | Why MongoDB is great for small Ruby apps

Why MongoDB is great for small Ruby apps


August 29, 2011


Most of the reasons I’ve seen for creating apps with MongoDB have to do with scalability. Now I’ve seen that go well enough and I’ve seen it go REALLY bad. Like when your database is big enough that it’s indexes won’t fit into memory (which is more of an issue with MongoDB because MongoDB takes up much more space than a normal DB does, that goes for indexes as well). Those issues aside however the biggest reason I like using it is for rapid prototyping on small Ruby projects. I’ve found it really pleasant to be able to start using the DB and not worry about DB Schema. Granted you are playing with fire there since you can easily end up with a database that is a complete mess, but for smaller apps it’s less of an issue. And since it’s less of an issue, here is why I like using it:

 

No migrations – Just create a model and you are off and running. Doesn’t get faster than that and if you are worried about rapid prototyping I’ve found it a huge help to cut out a lot of the red tape involved in getting my apps up and running. If you want to create an account model with a name, account number and address this is all you have to do:

def sample_method
  class Account
    include Mongoid::Document
    field :name
    field :number
    field :address
  end

  a = Account.new
  a.name = "Mrs. Butterworth"
  a.number = 23231
  a.address = "1 Butter Ave."
  a.save!
end

And that’s it. The road meets the rubber and you are off. No more running migrations. Save time, get it working, if you don’t like it you can still make it with MySql and Active Record.