简体   繁体   English

护照mongoStore在Mocha测试中引发连接错误

[英]passport mongoStore is throwing connect errors in mocha tests

It is only occassionaly but its annoying enough: 它只是偶然的,但很烦人:

I have auto_reconnect: true which didn't seem to fix the problem. 我有auto_reconnect: true ,这似乎无法解决问题。

mongoStore = require('connect-mongo')(session);

// Persist sessions with mongoStore
app.use(session({
    secret: 'ever loving sound of frogs',
    store: new mongoStore({
        url: config.mongo.uri,
        collection: 'sessions',
        auto_reconnect: true
    }, function () {
        console.log('db connection open');
    })
}));

I still get this error occassionally when I run my unit tests: 运行单元测试时,有时仍会出现此错误:

debugger listening on port 56141
Error: Error setting TTL index on collection : sessions

In my experience that error message is basically what you see when connect-mongo can't connect to the database, for a variety of reasons. 根据我的经验,由于各种原因,当连接mongo无法连接到数据库时,基本上会看到错误消息。

In your case, considering it sounds like it's intermittent, perhaps you might have a race condition between initialization and when it is used. 在您的情况下,考虑到听起来好像是断断续续的,也许您可​​能在初始化和使用之间有竞争条件。 Take a look at the following article below and maybe it will help to break out your connection step as shown there, and make sure it has completed before proceeding to creating the store. 请看下面的以下文章,它可能会有助于打破此处所示的连接步骤,并确保它已完成,然后再创建商店。

..and, some other related links: ..,以及其他一些相关链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM