I have a problem modeling data structure in MongoDB. Here are my considerations:
- Let's say I have a parent object and a child object. Parent can contain many child objects. And I can have probably infinite number of parent objects (but let's define it as hundreds of thousands) and probably at most one thousand child object in one parent. The problem is that one of parent's property is calculated basing on children list. So, when I will link relationship to the parent in child, then I will have to update parent when adding a new child, which isn't supported in MongoDB as atomic operation (two different documents). When I embed children list into parent, then I probably wouldn't have to store this property in parent, because it could be calculated on the fly. Additionally, if I retrieve list of parents, all children will be downloaded, which isn't entirely good for a page with parent only list. Also, on parent details I would like to make a pagination for child objects, but they always will be downloaded all, right? Which approach is better here?
- Dictionaries in MongoDB. Let's say I have a property which is a dictionary value and have a document which holds this dictionary. And it can look like [ObjectId1: 'A', ObjectId2: 'B', ObjectId3: 'C']. Now, if I will define property in document to be linked to this one, I have a problem how can I join this? If I retrieve objects with property from this dictionary, how can I make it so that dictionary values are in the property instead of object ids? If I would insert there values, then I have no control over what value is inserted there and whether it is valid.