search

Home  >  Q&A  >  body text

javascript - mongodb Authentication failed.

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?

黄舟黄舟2728 days ago1172

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-06-27 09:20:13

    Check whether the user jeremy you created is created in the mysessions database.

    For reference.

    Love MongoDB! Have fun!

    reply
    0
  • Cancelreply