What is the best possible user multi-currency wallet database design?

Viewed 191

I'm using mongodb/mongoose, my app new requirements is to have multiple currencies, and each user can have a different balance for each currency. ex: A user can have 30 USD, 100 EUR, 200 EGP. No exchange from one currency to another, just a bunch of currencies. At the moment we don't have any currencies, just a field called "balance" which contains user's balance. My solution is to create a table for currencies, each with an _id and a name. but when it comes to user balance I can't determine what is the best solution to make increasing and decreasing user balance easy, the only solution that crosses my mind is making balance field an array of object

balance: [{ currency: "CurrenyId", amount: 50 }, { currency: "CurrenyId", amount: 100 }]

But the problem with this approach is updating balance would be troublesome, Would you suggest a better solution ? thanks

0 Answers
Related