should I create a seperate model (collection) for this?

53 Views Asked by At

i am building a small web app with MERN, i have a collection that holds "name, email, password, avatar url, and date" and i am going to add to the users some info like a "bio, hobbies(array), "visited countries(array), and another array"

question is, should i create a diffrent model for the users info, and add owner field that refers to the other model?. or should i put all of them there,

also i might add the following and followers option in the future.

1

There are 1 best solutions below

1
Kien On BEST ANSWER

The user's info should be in the user collection, I could see there is no reason to have a separate collection for it. If you want to reduce the responses from listing users, you could use populate to remove unnecessary fields.

Regards to the following and followers, I think there are 2 approaches:

  • Adding a new field which used to store id and necessary metadata (name, avatar) of users to the existing collection
  • Create a new collection which is a combination of users and users they are following, or are followed. You then could use Virtual to get this information from the User collection.

Personally, I prefer the first approach although it requires more effort to maintain the list to be accurate. E.g remove an item out of the list when your follower stops following you.