Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialroger gold
30 PointsIt is wise to Store all user data in session or unique id of database?
I am making a simple social networking site in Express Node Js Using mongo db. There are users info in database that is to be displayed in many pages.
If I store a user Id of my db collections as a session variable, each time I should write db query to find user of that ID and display their info. Would it better if I store all the info of that user as a session variable.
Or, there is another better approach
1 Answer
Tobiasz Gala
Full Stack JavaScript Techdegree Student 23,529 PointsYou hold session variable for a certain amount of time (if the user is not active anymore) or until you destroy session (logout). In other words why you need to retrieve information over and over when you can hold it in session... use session :)