How would you add User Model/Schema for working project?

hi,
im trying to now add “authentication” to this simple project I’m trying build. However the project is working fine without any authentication
The project is simple contact book to practice database query where I can so far create a user and address. I can associate the address to the user.
So the pic above is the data model at the moment, now I’m trying to add a User model which would contain user login name, and password, which will embed the Contact Model. I’m trying to have a user who have logged in, to access to the application like creating contact and seeing things they have in their contact
Is my approach the right way? I’m using Express, MongoDB, and Node.js
how would you model User who can log in and save the contacts? any ideas or tips would be appreciated

Hi @M_San_B ,

A basic approach will be to hold a user collection where a user profile is stored and updated.

Than each contact document can have an owner details. Those details depand on the application views and what data needs to be presented or filtered.

The bare minimum seems to be storing a userId per contact or maybe an array of users if there are multiple users sharing the same contact data.

When you login and identify the user you can index and pass this userId to the contact collection query and fetch only relevant contacts.

Let me know if that makes sense.

Thanks
Pavel

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.