Now that we have a high-level view of our architecture, let's define our models and see how they interact. This will give you a high-level view of how you are going to store your data in the database. Also, it will reflect the connections between different entities and you can decide, in the case of MongoDB, what documents will be embedded and which ones will be referenced.
In the earlier Expense Tracker application, we concluded that there is a way to work with monetary data in JavaScript and MongoDB. It only needs extra application logic to handle the Exact Precision solution.
Because we are working with Mongoose as our ODM for Mongo, we can define a custom model for monetary data. I know it sounds strange, but it will give us the upper hand by defining virtual properties and reusing the money data type in our application.
Let's create a file called core/models/money.js
and add the following Mongoose schema:
'use strict'; const DEF_CURRENCY = 'USD'; const...