简体   繁体   中英

How should app data be stored in a database?

If I have an app that has foundational values that can be changed, like categories and a service fee, how do I store these in a database? For example, let's say that a service fee of 5% applies to User 1 who is located in Seattle, WA and a fee of 7% should apply to User 2 located in Manhattan, NY.

Right now I have an admin panel that can set the service fee, but it would be across the entire app since it stores this value in a MongoDB database along with other app "settings".

Is storing a value like this (or product categories) in a database the proper way to do this, and I simply check the user location when they use the app to determine the correct service fee/categories, or should I be taking another approach?

While the values themselves for any given fee might change for each user, presumably they're all the same sets of fees across everyone. In an effort not to over-engineer a solution, I'd just create a table in which you assign an ID and have a decimal column for each of your various fees. In your user table create a foreign reference to the ID of the fees assigned to any given user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM