|
Currently we store the documents for both navigational directions of a bi-directional association in the same collection in MongoDB when using the COLLECTION_PER_ASSOCIATION strategy:
{
"_id" : { "owners_id" : "owner0001" },
"rows" : [
"accountABC",
"accountXYZ"
]
}
{
"_id" : { "bankAccounts_id" : "accountABC" },
"rows" : [
"owner0001"
]
}
{
"_id" : { "bankAccounts_id" : "accountXYZ" },
"rows" : [
"owner0001"
]
}
This requires to store the column name of the ids as we otherwise wouldn't know which side of the association a given record represents.
An alternative would be to use two separate collections for the both directions of the assocation, which allows for a more compact id syntax (assuming non-compound keys):
{
"_id" : "owner0001",
"rows" : [
"accountABC",
"accountXYZ"
]
}
{
"_id" : "accountABC",
"rows" : [
"owner0001"
]
}
{
"_id" : "accountXYZ",
"rows" : [
"owner0001"
]
}
In a way that would closely resemble the IN_ENTITY strategy, only that the assocations are not stored as sub-documents within the entities but as separate documents. It should also be a bit more efficient as the key is not structured and only the half of documents needs to be searched when accessing one side of an association.
|