I had multiple use
of the session and cookieParser
. This caused the problem.
Connect-mongo not creating database
-
05-10-2022 - |
Pregunta
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 sessionID
s, 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).
Solución 2
Otros consejos
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.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow