想想一个标准的城市建设者游戏。 你有城市,每个城市都有单位,每个单位都有装备(装备),城市本身有更多的装备(没装备,他们在某个地方的盒子里,嘿)。
A)首先,我考虑制作3个系列。
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)然后我把它变成了:
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)最后,这是一个集合:
Cities:
{
_id, name, locationX, locationY,
units: [ {name, unitTye}, {name, unitTye}... ],
items: [ {name, itemType, unitEquipped}, {name, itemType, unitEquipped}... ]
}
注意单位不再有city_id,因为没有必要。 谁能告诉我这3种风格的优缺点?我认为最后一个数据冗余最少,但如果我想要locationX,我必须处理该文档中的其他信息,对吗?