0

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.

ProMaker Dev
  • 105
  • 1
  • 2
  • 12
  • you better use the same collection for these arrays as all of the properties e.g. hobbies, visited_countries, followers are linked/related to the user so you should put them in a same collection. And also on second level of nesting objects you can directly insert objects into arrays so it will be easy. – Usama Tahir Aug 27 '20 at 23:50

1 Answers1

0

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.

Kien
  • 133
  • 1
  • 7