Take the 2-minute tour ×

I am using mongodb in my rails app with odm mongoid

My questions are easy:

a) when associations between objects should be embedded or referenced?

b) how does this affect the application performance?

Thank you very much!

share|improve this question
It was discussed multiple times. Short answer: "it all depends on your app, data and access patterns". –  Sergio Tulentsev Aug 4 '12 at 12:39
Take a look here: mongodb.org/display/DOCS/Schema+Design –  Sammaye Aug 4 '12 at 12:41
Thank you guys! –  hyperrjas Aug 4 '12 at 17:15

1 Answer 1

up vote 2 down vote accepted

Referenced relationships require multiple db lookups; embedded relationships don't. But referenced relationships are easier to work with (especially if you are just starting out with your app and/or with mongo). I would recommend that you stay with referenced relationships until you have a better sense of the shape of your app and your data needs; at that point you can denormalize your data by switching some of those referenced relationships to embedded.

I would also recommend https://github.com/dzello/mongoid_alize to help with denormalization.

share|improve this answer
Thank you very much! –  hyperrjas Aug 4 '12 at 17:08

Your Answer


