Search code examples
node.jsmongodbexpressmongoosenodejs-server

Can I maintain two user collections in MongoDB?


I am new to node and practicing it...

I have a requirement where user will have a profile section Where he fills lot of data like his educational details , employment details , address , and many other details.

As of now I am creating user collection on signup.

Can I maintain the a separate collection for profile details and whenever user details updated I will update initial registered collection also

Is this a good approach or do I need to maintain only one collection.

Can some one suggest me which is the best


Solution

  • it is not uncommon to have more than 1 or more user collection, for at the very least, passwords should not be in the same collection of other public data.

    You could also end up with different user collection of

    • personal data
    • sensitive data
    • browsing history

    etc. All referenced by the same user _id

    Data however, should in the best scenario, not be overlapped. Hence so there should only a single source of truth of value, except for _id which is used for referencing.

    If you update a value in one collection, you should not need to update same value in another colletion.