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 trial

JavaScript User Authentication With Express and Mongo Improving the App with Custom Middleware Using MongoDB as a Session Store

What about storing multiple sessions for each user that is logged into the system? This example only shows 1 session?

So what about handling the case when multiple users have logged into the API and have created individual sessions? How does one handle that logic? I am building an API with many users and storing their sessions in Mongo. However, I can only get 1 object ever stored into the sessions collection of Mongo. It seems that the latest user to log into the system overwrites the previous users session. Can you help handle a situation like this?

hchris
hchris
Courses Plus Student 11,116 Points

Hi,

Could you post the code where you're connecting to the db and then storing the session? I just tested the code from the video in 2 different browsers, and I have 2 session objects stored in my collection.

1 Answer

I was testing from the same browser so that is why it wouldn't create multiple sessions. Thanks though!