Node provides services. In the development and production environment, the session data is placed in the memory. When it goes online, the heap out of memory appears, so connect-mongo is used to store the session in mongodb. Initially The test is written like this
var dbUrl = 'mongodb://localhost/mysessions';
mongoose.connect(dbUrl,{useMongoClient: true});
var options = {
url: dbUrl,
collection: 'sessions'
};
app.use(session({
secret: '12345',
name: 'test',
cookie: {maxAge: 1 * 60 * 1000},
resave: false,
saveUninitialized: true,
store: new MongoStore(options)
}));
But later changed dburl to:
var dbUrl = 'mongodb://jeremy:123456@localhost/mysessions';
在启动服务时报错了:
What is the reason and how to solve it?
Check whether the user jeremy you created is created in the mysessions database.
For reference.
Love MongoDB! Have fun!