We do the exact same thing at Buildy, but in Python. Here's the class:<p><a href="https://gist.github.com/irskep/9099262" rel="nofollow">https://gist.github.com/irskep/9099262</a>
As we gradually migrate data from MongoDB to MySQL, this code has been hugely helpful. It is making the transition as smooth and efficient as possible. I hope others can get some value out of the gem as well.