Reputation: 109
I'm building a MEAN stack application with passport auth and just wanted to know the best approach to storing and getting user specific data.
So say for a simple example I had a collection of users and a collection of fruits stored inside a database.
The user can add a favourite fruit, which will be stored in the fruits collection against their specific user ID. When they return to the app at a later stage, I can get all the favourite fruits for that specific user and display them on the page.
Would the best approach be to store these fruits in a separate collection?
Or should they be stored in that specific user document in the users collection?
In terms of then getting the data back, would I have to check the user ID of the logged in user and then get all of the favourites for that user ID?
Thanks
Upvotes: 0
Views: 302
Reputation: 94
I think you are asking about reference or embedded. This link MongoDB relationships: embed or reference? may answer your questions.
Upvotes: 1