8

what are the key points that one should think of while choosing between embeds_many and references_many (or embeds_one and references_one) in Mongoid?

I'm currently preferring embeds_many over references_many, but that is resulting in too many nested embeds_many'ies and I'm worried that it might add unnecessary overhead to the database.

Vikrant Chaudhary
  • 11,089
  • 10
  • 53
  • 68

2 Answers2

8

The most important thing to be aware of is the 4 MB limit for each document in MongoDB - by using references instead of embedding documents, you can keep the size of your documents lower.

Other information about the differences can be found here.

crazycrv
  • 2,395
  • 2
  • 19
  • 20
Rich
  • 15,602
  • 15
  • 79
  • 126
1

I think that you should to use "entity-object" and "object-value" definitions from DDD. For entity use reference,but for "object-value" use embed document.

And check this question for more details about entity vs object-value.

Community
  • 1
  • 1
Andrei Andrushkevich
  • 9,905
  • 4
  • 31
  • 42