Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating an Activerecord database to Mongoid

I'm new to Rails programming. I was thinking about implementing devise and omniauth authentication per railscast tutorial. Since I don't know mongoid yet, I was planning on just starting with Activerecord. Eventually I want to use Mongoid I think.

How would I do a migration from Activerecord to Mongoid?

I just want to get rolling with my project. Especially when I have few users Activerecord will probably be sufficient. I've never done this before, so hopefully someone can tell me if this approach is going to be way more trouble than it's worth. Does it make more sense for me to take more time now to learn mongoid now instead?

I'm looking forward to hearing from you Rails veterans.

like image 783
Cyrus Avatar asked Apr 04 '11 21:04

Cyrus


1 Answers

You build your models, controllers and views exactly the using mongoid as you do using ActiveRecord, so there's little difference there. The big difference is in the way your data is actually stored and retrieved, which affects your models, which directly impacts your code.

A schema-less database like mongoDB can't protect you like MySQL can, and there is no simple way to do migrations using Mongoid.

If you're starting out, you should probably go with ActiveRecord just because the a lot of the information out there relies on you using ActiveRecord with a relational database.

However, a switch to mongo/mongoid is definitely worth any perceived pain, but unless you've used a relational database and ActiveRecord, you may not appreciate just how awesome mongo/mongoid can be!

like image 150
BenB Avatar answered Sep 23 '22 23:09

BenB