Consider:
Summaryschema with aminimum_scorepropertyPersonRecordschema with ascoreproperty- A single
Summarydocument should containminimum_scoreof all thePersonRecorddocuments.
Following two actions are done in a transaction:
- Insertion of new document in
PersonRecordcollection - Update
Summarydocument'sminimum_scoreproperty using{ $min: personRecord.score }
However, there is another requirement to allow a person to delete his PersonRecord document. So consider the scenarios such as following:
- All of the persons delete their
PersonRecorddocuments - One person deletes his
PersonRecorddocument while another person is inserting a new one.
How can we handle the scenarios in mongodb (mongoose) if we ALWAYS want to have the correct minimum_score value in Summary document?
I can think of achieve this is using the principle of eventual consistency. Is there any other way?