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

时间:2021-11-02 03:58:08

I have my MongoDB running on a Cloud VM , and NodeJS Server running on another Azure Cloud VM. I use Mongoose in the Application for MongoDB Connect. Keep getting this timeout issue every day? Any suggestions

我让我的MongoDB在云虚拟机上运行,​​而NodeJS服务器在另一个Azure云虚拟机上运行。我在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 个解决方案

#1


2  

Refer this link :- http://www.slideshare.net/VictoriaMalaya1/mongo-db-in-windows-azure

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

MongoDB in Windows Azure:- Drawbacks and workarounds : connection timeout for .Net driver MongoDB Client Uses .Net driver socket timeout exception Windows Azure terminates an inactive connection after roughly 4 minutes of idling MongoDB suggests: Set the max idle connection time on the driver: MongoDefaults.MaxConnectionIdleTime = TimeSpan.FromMinutes(1); My experience: Add following options to connection string: maxIdleTimeMS=60000;connectTimeoutMS=60000;socketTimeoutMS=60000 Sample of connection string: connectionString="mongodb://localhost/mydb ?maxIdleTimeMS=60000;connectTimeoutMS=60000;socketTimeoutMS=60000"

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”

#1


2  

Refer this link :- http://www.slideshare.net/VictoriaMalaya1/mongo-db-in-windows-azure

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

MongoDB in Windows Azure:- Drawbacks and workarounds : connection timeout for .Net driver MongoDB Client Uses .Net driver socket timeout exception Windows Azure terminates an inactive connection after roughly 4 minutes of idling MongoDB suggests: Set the max idle connection time on the driver: MongoDefaults.MaxConnectionIdleTime = TimeSpan.FromMinutes(1); My experience: Add following options to connection string: maxIdleTimeMS=60000;connectTimeoutMS=60000;socketTimeoutMS=60000 Sample of connection string: connectionString="mongodb://localhost/mydb ?maxIdleTimeMS=60000;connectTimeoutMS=60000;socketTimeoutMS=60000"

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”