0 votes
1 view
in SQL by (47.8k points)

I'm new to MongoDB--coming from a relational database background. I want to design a question structure with some comments, but I don't know which relationship to use for comments: embed or reference?

Do I have to use ref not embed? Then I have to create a new collection for comments?

2 Answers

0 votes
by (107k points)

Embed is good if you have one-to-one or one-to-many relationships between entities, and reference is good if you have many-to-many relationships.

0 votes
by (78.7k points)

While dealing with unstructured data, in MongoDB, embedding may be better for all the instances where there is a strong correlation between the data. If something feels strange while shaping the data with embedding (such as relationships that result in data duplication under multiple top-level objects), you can switch to referencing. Referencing should be used more delicately as there are restrictions to referenced documents and references are less effective as compared to the embedded.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...