Hello, is it an acceptable/ common practice in a multidocument environment to run an aggregation query to get the refreshed data to overwrite the old information with and this way keep the documents up to date post-change?
Product documents A, B and C have a field that references Container A.
Stores financial data on products that each container document contains (has products that point to it).
Product B is moved from Container A to Container B by changing the product’s local field value
Containers A and B need to reflect this change. The product A no longer points to Container A, so the latter’s embedded financial data needs to be refreshed to reflect this. Container B needs to have its embedded financial stats updated to reflect the new product pointing to it.
WRAPPED IN TRANSACTION:
Containers A and B run individual aggregation queries to recalculate various financial data by getting the latest information on what products now point to them. The result of this aggregation is then formatted and both of the containers are updated via the
update()query overwriting the outdated information.
Is this acceptable/ good/ common? Any better alternatives?