Scenario: Entity A is parent, B is child of A with 1 to many, C is child of B with 1 to many. Lets say: A is account, B in Contact & C is Address
We need to have entire structure in 1 document, so no sub collections & sub documents. For child entities we have 2 options: Map of Maps or Array of Maps. We are inclined towards 'Map of Maps' as we can't set a unique Id at array on top level. It has to be a field inside the array and then its difficult in script to search with it as we need to loop through all records.
So configuration will look something like this: - Define a field of type Map inside Account with name Contact - Contact will only have fields of type Map inside it. Each map field name is unique id of contact. So lets say 2 maps: ContactId1, ContactId2 - Inside ContactId1 map we will have some Contact field like names and then we will have another field 'Address' of type Map. - 'Address' will only have fields of type map inside it. Each map field name is unique id of an Address : AddressId1, AddressId2 - Map AddressId1 will have fields inside it for address i.e. StreetName, No, City, Zipcode, etc
Questions:
- Is 'Map of Maps' datatype better approach then 'Array of maps' datatype for our scenario
- What are the pros and cons of both approach
Account{
Name: "My Account Name"
Contact:
Contact123:
FirstName: "F1"
LastName: "L1"
Address:
Address1231:
Street: "Street1"
City: "City1"
Address1232:
Street: "Street2"
City: "City2"
Contact234:
FirstName: "F2"
LastName: "L2"
Address:
Address2341:
Street: "Street3"
City: "City3"
Address2342:
Street: "Street4"
City: "City4"
}