0

I'm using express-session and am now wanting to use connect-mongo to persistently store session. I have seen the docs and some tutorials and mostly understand how it works, but I assume you need a mongoDB instance setup in the first place so connect-mongo has something to connect to?

Some examples I have seen involve connecting to a test mongoDB on localhost, so is it just a case of installing mongoDB as standard and then using that instance?

mindparse
  • 6,115
  • 27
  • 90
  • 191

1 Answers1

2

Yes, you can either use a current connection or tell connect-mongo to use a new connection.

Using a current connection:

app.use(session({
    store: new MongoStore({ db: dbInstance })
}));

Where dbInstance is your current connection.

Using a new connection:

app.use(session({
    store: new MongoStore({ url: 'mongodb://localhost/test-app' })
}));

url is just a traditional mongodb connection string.

Ash
  • 6,483
  • 7
  • 29
  • 37