문제

My connection to my mongo database will close or timeout if left in active. I'm getting the following error when I leave my app in active "no open connections"

My mongo DB is running in a replication set up on AWS. I'm using the following options when connecting using mongoose. I'm unsure if any other flags should be set. I was basing my options on teh monodo node driver doc @ http://mongodb.github.io/node-mongodb-native/api-generated/server.html.Users will be in my applicaiton for 8+ hours at a time and I don't want anything to timout when they go to lunch or leave for a meeting.

  MongoOptions : {
      user: 'root',
      pass: '********',
        replset: {
            auto_reconnect: true,
            poolSize: 25,
            socketOptions: { keepAlive: 1 },
            ssl: true,
            sslCert: fs.readFileSync('./server/config/ssl/mongodb-cert.crt'),
            sslKey: fs.readFileSync('./server/config/ssl/mongodb-cert.key')}
    }

mongoose.connect('mongodb://server.com:27017', config.MongoOptions);

enter image description here

도움이 되었습니까?

해결책

The connection getting closed turned out to be another issue that was causing the problem.

We have a replicate set running w/ SSL and are able to keep the connection up for days using the following config:

  MongoOptions : {
      user: 'ssssss',
      pass: 'xxxxxx',
        replset: {
            auto_reconnect: false,
            poolSize: 10,
            socketOptions: { keepAlive: 1  },
            ssl: true,
            sslCert: fs.readFileSync('./server/config/ssl/mongodb-cert.crt'),
            sslKey: fs.readFileSync('./server/config/ssl/mongodb-cert.key')}
    }

다른 팁

Try adding

connectTimeout: 43200000

that should be good for 12 hours

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