So these are your relation options and I hope that the examples kind of gave you a feeling for how to
think about relations and when to use which approach, it always depends on your application needs,
how often you change data, if snapshot data does suffice
and how large your data is, how much data you have. In general, with embedded documents,
the idea is to group data together logically and often, that makes sense and gives you an easier time
when fetching the data
and that is great for data that belongs together, for one-to-many or one-to-one relations and that is
not really overlapping with other data,
so you got no many-to-many relation and where you're also not in danger to hit any limit imposed
by mongodb and where you also don't need to split your data for application needs
like we had in the person and car example here. You should avoid super deep nesting because you can only
nest for 100 levels
as you learned and again, keep that 16mb limit per document in mind
and that also contains the embedded documents,
so it's not 16mb per embedded document but for the overall document. That is a lot
but for New York City with all its citizens, you would probably reach it.
The alternative then is the reference approach, there you split your data across collections and that is
great for related data, that is shared,
so many-to-many relationships in the end or it's great for data where you would have a lot of duplicates
which you'll update a lot and therefore you have the danger of needing to update a lot of documents
all the time which is bad and it's also a great solution if you need to overcome any nesting or size
limits,
then you can simply split it across collections because that of course,
well basically allows you to remove some levels of nesting.
These are your options,
there is no general formula but if you keep these general things in mind, how do I use my data,
how often do I use it,
how often do I change it and how is it related, one-to-one, one-to-many, many-to-many,
if you go through all these points, you should be able to really create relations that work for you.