Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing between embeds_many and references_many in Mongoid

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.

like image 606
Vikrant Chaudhary Avatar asked Feb 16 '11 15:02

Vikrant Chaudhary


2 Answers

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.

like image 192
Rich Avatar answered Nov 15 '22 18:11

Rich


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.

like image 1
Andrei Andrushkevich Avatar answered Nov 15 '22 18:11

Andrei Andrushkevich