Hello everyone, a newbie in mongodb and document schema modeling. I have a question about techniques to keep extended references up to date. Let’s say I have two collections: an aliment collection and a meal collection. Each aliment is created and update by the user. Each aliment has a name and a list of nutritional values. Each meal is created and updated by the user. Each meal has a name, a list of extended reference to Aliments and a computed nutritional values based on the nutritional values of each aliment of the meal.
Assume now that the user changes the name from PASTA to PASTA Barilla. What are the best techinques to propagate that change to all meals that reference the old PASTA aliment?
For the moment I can think of the following:
When the user updates the aliment, I check each Meal and update the extended reference.In this case, I will have one transaction updating the Aliment document and a second bulk operation to update all the meals.
But what happen if for some reason one meal update fails because the user updated the meal in the meantime?