Think of a standard city builder game. You have cities, each cities have units, each units have gear(equipped) and the city itself has more gear(unequipped, they are in a box somewhere, heh).
A) First off, I thought of making 3 collections.
Cities: {_id, name, locationX, locationY}
Units: {_id, name, city_id, unitType}
Items: {_id, name, itemType, unitEquipped} where unitEquipped was optional( item belonged to the city).
B) Then I turned it into:
Cities: {_id, name, locationX, locationY}
Units: {_id, units:[ {name, city_id, unitTye}, {name, city_id, unitTye}... ]}
Items: {_id, items: [ {name, itemType, unitEquipped}, {name, itemType, unitEquipped}... ]}
C) And finally, this is one collection:
Cities:
{
_id, name, locationX, locationY,
units: [ {name, unitTye}, {name, unitTye}... ],
items: [ {name, itemType, unitEquipped}, {name, itemType, unitEquipped}... ]
}
Notice how units no longer have a city_id in them as there is no need to. Can anyone tell me the pros and cons of these 3 styles? The last one i think has the least redundant data but if I want locationX, I have to deal with the other info in that document, right?