How to organize mongodb structure in order to avoid the need for joins? -
think of standard city builder game. have cities, each cities have units, each units have gear(equipped) , city has more gear(unequipped, in box somewhere, heh).
a) first off, thought of making 3 collections.
cities: {_id, name, locationx, locationy} units: {_id, name, city_id, unittype} items: {_id, name, itemtype, unitequipped} unitequipped optional( item belonged city).
b) turned 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) , finally, 1 collection:
cities: { _id, name, locationx, locationy, units: [ {name, unittye}, {name, unittye}... ], items: [ {name, itemtype, unitequipped}, {name, itemtype, unitequipped}... ] }
notice how units no longer have city_id in them there no need to. can tell me pros , cons of these 3 styles? last 1 think has least redundant data if want locationx, have deal other info in document, right?
Comments
Post a Comment