mongodb-js/connect-mongodb-session

Are the sessions stored in db.sessions for the MongoDB database used?

gauravbharat opened this issue · 3 comments

Greetings!

First of all thank you for this package!

I have two questions -

  1. When using this package, are the sessions stored in db.sessions for the MongoDB database used? I don't see any records in the db.sessions.
  2. At what interval the sessions may be cleared from the database whose "req.session.cookie.expire" is set to "false"?

I am connecting the following way, reusing the mongoose.connection to database -
const session = require('express-session');
const MongoDBStore = require('connect-mongodb-session')(session);
app.use(session({
secret: "KfCTA8vDlpXzKtDBFGpj/hVWdsU=",
resave: false,
saveUninitialized: false,
store: new MongoDBStore({ mongooseConnection: mongoose.connection })
}));

Sorry new to using the github.

I tried with the following but the connection failed without any error returned (tried both with and without the collection: 'mySessions' argument) -
var store = new MongoDBStore(
{
uri: "mongodb://localhost:27017/yelp_camp",
databaseName: 'yelp_camp',
collection: 'mySessions'
},
function(error) {
console.log("error connecting MongoDBStore: " + error);
});

The console printed just the following -
error connecting MongoDBStore: undefined.

Seems that it never connected to the database for the store part?

@gauravbharat I'm having the same issue. Did you get any fixes to this error?

  1. Yes, this package stores sessions in the sessions connection by default. Make sure you're connected to the right database (try running db to get the database name, and show dbs to see what databases are available). You can use the collection option to overwrite this.

  2. connect-mongodb-session won't clear sessions in that case, so it's up to you to decide when to clear them.

@uma-08 this isn't an error. If error is undefined in the new MongoDBStore() callback, that means no error occurred.