2017-02-18 81 views
0

以下是heroku日誌的輸出。我嘗試設置連接參數Heroku nodejs/mongoose和mLab應用程序崩潰,超時

socketTimeoutMS: 0, 
    connectionTimeout: 0 

但仍occures

[web.1]: events.js:160 
[web.1]:  throw er; // Unhandled 'error' event 
[web.1]:  ^
[web.1]: 
[web.1]: Error: connection timeout 
/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:169:17) 
........ 
[web.1]: npm ERR! Linux 3.13.0-105-generic 
/.heroku/node/bin/npm" "start" 
[web.1]: npm ERR! node v6.9.5 
[web.1]: npm ERR! npm v3.10.10 
[web.1]: npm ERR! code ELIFECYCLE 
+0

您使用的是什麼版本的貓鼬的,什麼是MongoDB的版本也MLAB –

+0

是你確定你已經爲mongo實驗室提供了正確的地址和認證密碼? –

+0

@RaviShankar是的。即使它曾經工作過。 – rahmanisback

回答

1

我接觸MLAB爲。這是他們的支持人員的迴應:

我們經常建議從Heroku連接時連接超時30秒。你可以看到我們的建議的貓鼬的配置在這裏: https://gist.github.com/mongolab-org/9959376

下面是在GitHub的要點連接配置:

// mongoose 4.3.x 
var mongoose = require('mongoose'); 

/* 
* Mongoose by default sets the auto_reconnect option to true. 
* We recommend setting socket options at both the server and replica set level. 
* We recommend a 30 second connection timeout because it allows for 
* plenty of time in most operating environments. 
*/ 
var options = { server: { socketOptions: { keepAlive: 300000, connectTimeoutMS: 30000 } }, 
       replset: { socketOptions: { keepAlive: 300000, connectTimeoutMS : 30000 } } };  

var mongodbUri = 'mongodb://user:[email protected]:port/db'; 

mongoose.connect(mongodbUri, options); 
var conn = mongoose.connection;    

conn.on('error', console.error.bind(console, 'connection error:')); 

conn.once('open', function() { 
    // Wait for the database connection to establish, then start the app.       
});