I'm trying to develop an application that would allow organizations to track their inventory and margins for the products/services they sell. I've started writing the back-end using NodeJS/Express/Mongoose.
However, I'm struggling with the idea of how to set up the data model. This would be a subscription-based model so each organization subscribing to my application would need to be a separate database in MongoDB so all data is strictly separated from other customers of the application.
The way I currently started to design the application is:
- Allow a user to signup and generate a unique identifier for that user's organization which is stored in a separate 'Master' database in MongoDB that exists for the sole purpose of storing that identifier.
- Create a new connection string to the MongoDB database using the unique id from step 1 as the database's name
- Once the connection is made with the new database, generate all other records such as user details, etc...
The approach works but it feels kind of amateur and I'm sure there are better ways of doing this. Does anyone have a piece of good advice on how to tackle this problem?
Many thanks in advance!
Regards, Stefano