2

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!

Community
  • 1
  • 1
hyperrjas
  • 10,666
  • 25
  • 99
  • 198
  • It was discussed multiple times. Short answer: "it all depends on your app, data and access patterns". – Sergio Tulentsev Aug 04 '12 at 12:39
  • Take a look here: http://www.mongodb.org/display/DOCS/Schema+Design – Sammaye Aug 04 '12 at 12:41
  • Another link [http://openmymind.net/2012/1/30/MongoDB-Embedded-Documents-vs-Multiple-Collections/](http://openmymind.net/2012/1/30/MongoDB-Embedded-Documents-vs-Multiple-Collections/) – tfentonz Aug 04 '12 at 19:11

1 Answers1

2

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.

Shailen Tuli
  • 13,815
  • 5
  • 40
  • 51