Consider the following two schemas:
Block{
_id
type
desc
size
}
User{
_id
name
email
}
One User can refer to a Block multiple times.
Also, one User can refer to multiple Blocks. (Typical One to Many)
Clearly, it’s not the typical One to Many relations.
Considering that we don’t require the Users who are referring a block. We can safely ignore the relation from Block to User!
How shall I model it?
Say I have the following Block:
{_id: 1, type: 'ABC', desc: 'ABC Block', 'size': 20}
{_id: 2, type: 'DEF', desc: 'DEF Block', 'size': 40}
{_id: 3, type: 'GHI', desc: 'GHI Block', 'size': 60}
A user instance: (without blocks)
{
_id: 100,
name: 'A',
email: '[a@abc.com](mailto:a@abc.com)',
}
Shall I model the User with Blocks reference like the following?
{
_id: 100,
name: 'A',
email: 'a@abc.com',
1: [
{_id: 100, 'value': 100, 'last_edited': 'DATE'},
{_id: 200, 'value': 100, 'last_edited': 'DATE'},
],
2: [
{_id: 400, 'value': 120, 'last_edited': 'DATE'},
]
}