Loving MongoDB but Missing Transactions

I’ve been venturing into the world of MongoDB via Mongoid in a Rails app. On one hand it’s a breath of fresh air (no migrations, flexible schemas etc.) but on the other hand I really, really miss transactions.

If somebody asked me if I used transactions much in MySQL, I would probably have said no… however, now that I don’t have them I realise just how much I used them. Things that just work when using ActiveRecord such as creating a record and ensuring that an associated record gets created is sooo much harder.

MongoDB has “Atomic Operations” which means if you have an embedded relationship, all is good and the database will be rolled back if the entire document does not save. As soon as you have two top level collections and need to ensure that a record is created in both, things get a little hairy.

There seems to be a great deal of “if you need transactions just use a RDBMS” talk but what if you need a flexible schema and transactions, the last thing you want to manage is some kind of EAV system like Magento.

I’ve created a thread on the Mongo User forum with a typical example so feel free to join in the discussion. I’d love to hear experienced Mongo user’s views on how to overcome these kinds of situations and what kind of applications people are running with MongoDB.

Naming your Terminal tabs in OSX Lion

If you find yourself in the Terminal app with a bunch of tabs open, the default name of “bash” isn’t very useful when navigating between them. You can change the tab name via the UI by right clicking the tab, then clicking “Inspect Tab” and changing the window or tab names but this is somewhat long winded.

Below are a couple of bash functions I have in my “.profile” file to make this easier:


function tabname {
  printf "\e]1;$1\a"
}

function winname {
  printf "\e]2;$1\a"
}

Now you can easily name your tabs or windows with the following:


# Rename tab
tabname "Funky Tab"

# Rename window
winname "Funky Window"

Thanks to Bubu and Chris Page on the SuperUser site for the right codes.

Using Pow when developing Rails applications on OSX

I heard about Pow a while ago which is “a zero-config Rack server for Mac OS X” but never got around to giving it a go. I’ve just installed it and can instantly see that it is going to make developing with Rails (or any Rack app) a whole lot nicer, especially when dealing with apps that use subdomain account keys.

If you’ve not tried it yet, head over to the Pow website and get it installed with:

curl get.pow.cx | sh

Happy new year everyone!