Question

I am designing a nodejs lottery app, using MongoDB/Mongoose; it currently works with fake money.

I want users to continue to be able bet in a 'sandbox', with fake money, but I also want to allow users to use 1+ currencies, each currency with a different jackpot.

I'm looking for the best way to architect this within MongoDB:

Some possibilities:

  1. Use an entirely separate database for each currency. Users will have to have 1 account for each currency. Not ideal.

  2. Have 'bet', 'jackpot', etc. schemas have a 'currency' field. Probably easiest, but not sure if this is a relational way of thinking. It doesn't feel particularly elegant.

  3. Have 2 separate databases for 'bet' and 'jackpot', but a shared database with 'user' information. Since I do use 'populate' a couple of times, this may or may not be feasible.

I appreciate any thoughts on this.

Was it helpful?

Solution

When you want the lottery of each currency separated, you could put them in the same database, but in different collections for each currency. That way you can easily decide which data is currency-agnostic (like user accounts) and which data is currency-dependent (like bets).

Keep in mind, though, that any queries which get data about lotteries in different currencies will get more complicated, because you can only query one collection at a time. When you need a lot of such queries (like when the user has a dashboard where he sees all loteries he currently takes part in regardless of currency), you should rather go for the solution with a currency-field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top