문제

I have the following code to set up a session store with connect-mong

 var express = require('express');
 var MongoStore = require('connect-mongo')(express);
 var app = express();

app.use(express.cookieParser());
app.use(express.session({
secret: '1234567890QWERTY',
maxAge: new Date(Date.now() + 3600000),
store: new MongoStore({
    db: 'mydb',
    host: '127.0.0.1'
}),
 cookie: { maxAge: 24 * 60 * 60 * 1000 }
}));

In the requests and responses from the server I can see the sessionIDs, but the database is not created or if I create it the session collection does not gets filled. I do not receive any errors on the console.

I cannot find what am I missing ( using express 3).

도움이 되었습니까?

해결책 2

I had multiple use of the session and cookieParser. This caused the problem.

다른 팁

It happens because nobody connected yet to your express server. So there's no session to store.

Add

app.listen(3000, function() {
        console.log('now listening  on http://localhost:3000/'); 
});

At the end and connect to the server in your browser. Immediately you will get sessions collections in your Mongo db.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top