当mongodb不在同一个VM中时,mongodb连接超时

时间:2014-09-15 08:41:57

标签: node.js mongodb azure mongoose

我在Cloud VM上运行MongoDB,在另一个Azure Cloud VM上运行NodeJS Server。我在MongoDB Connect应用程序中使用Mongoose。每天都会收到此超时问题?任何建议

events.js:72
        throw er; // Unhandled 'error' event
              ^
    Error: failed to connect to [XXXXX.cloudapp.net:27017]
        at null.<anonymous> (/app/satwebnodev2/satwebnodev2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:546:74)
        at emit (events.js:106:17)
        at null.<anonymous> (/app/satwebnodev2/satwebnodev2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
        at emit (events.js:98:17)
        at Socket.<anonymous> (/app/satwebnodev2/satwebnodev2/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:533:10)
        at Socket.emit (events.js:95:17)
        at net.js:440:14
        at process._tickCallback (node.js:419:13)

1 个答案:

答案 0 :(得分:2)

请参阅此链接: - http://www.slideshare.net/VictoriaMalaya1/mongo-db-in-windows-azure

Windows Azure中的MongoDB: - 缺点和解决方法:.Net驱动程序的连接超时MongoDB客户端使用.Net驱动程序套接字超时异常Windows Azure在大约4分钟空闲后终止非活动连接MongoDB建议:在驱动程序上设置最大空闲连接时间:MongoDefaults.MaxConnectionIdleTime = TimeSpan。 FromMinutes(1);我的经验:为连接字符串添加以下选项:maxIdleTimeMS = 60000; connectTimeoutMS = 60000; socketTimeoutMS = 60000连接字符串示例:connectionString =“mongodb:// localhost / mydb?maxIdleTimeMS = 60000; connectTimeoutMS = 60000; socketTimeoutMS = 60000”< / p>