DEV Community

Discussion on: designing database

Collapse
 
rhymes profile image
rhymes

Hi Anshul!

I think role should be a separate entity. A user can have multiple roles, thus it'd b best not have role information (except the ids of the roles) in the user entity

Collapse
 
anshulnegitc profile image
Anshul Negi

I have edited question with an example.
Having multiple roles is another scenario.

Collapse
 
rhymes profile image
rhymes

I still think you should think ahead here and have a role entity, the user points to. A user "can" have multiple roles means they can still have 1 and be totally fine. It'd probably be harder to change the schema afterwards.

The balance is how costly joins with this new entity are, but I'm not familiar with MongoDB much to be of help for this. It probably depends also on the size of your DB

Thread Thread
 
anshulnegitc profile image
Anshul Negi • Edited

I am new to database design so considering present requirements I have designed a model. I have commented in the above post.