One-to-Many Relationship

Can someone explain why in One to many relationship quiz

Embed all the fields for a city as a subdocument in the corresponding county document. is not a valid way to represent this one-to-many relationship with the document model in MongoDB?

if this is invalid the what is the significance of embed in the “one” side?

Hi @Ayush_56509, it’s explained here:
… click on that link.

Hey @Ayush_56509

This would be true when the many side is more like a few and are not likely to change over time.

With the example you have given the number of cities in a country can be very large, think of the USA. Plus these cities change over time, with bigger cities engulfing smaller cities. Population changes each year. etc…

@natac13 That make a little sense, however do we have a range of how many subdocuments should be there so that it can be embedded else referenced?

Hey @Ayush_56509

There is not really a hard number. It would be a concern that is answered by your clients access patterns. Is the info to be embedded always called with the main document. Or if not then maybe maybe better to reference. Say the main document is of a person and the subdoc is their contact info. If I am querying for the person and always getting their social media info then better to embed.

Hope that helps

thanks @natac13 for clarifying :slight_smile: