In order to avoid the overhead involved in creating normalized data structures with lots of foreign keys and relationships, MongoDB DevOps may choose to store redundant information across collections. The main danger here is that if a change occurs in one collection, you, the developer, may need to ensure that a secondary update occurs in the collection with related information.
Accordingly, when a loan payment is accepted, the following secondary updates need to occur in the users collection:
- Add the amount paid to the amountPaid field for that borrower.
- Subtract the amount paid from the amountDue field.
Before we get started on the implementation, we need to first digress and discuss using listeners and events.