Node.js MongoDB连接在几天后关闭
因为我真的不知道可能是什么问题,所以我将复制粘贴错误。我搜索了谷歌,但到目前为止没有成功。我想代码的第一部分是问题所在,所以我只是添加了第二部分,以防它可能更有用。基本上,几天后,我的数据库停止工作,我不知道为什么。这是MongoDB的云版本,我使用NodeJs+ExpressJs+Mongoose。提前感谢您的每一个提示Node.js MongoDB连接在几天后关闭,node.js,mongodb,express,mongoose,Node.js,Mongodb,Express,Mongoose,因为我真的不知道可能是什么问题,所以我将复制粘贴错误。我搜索了谷歌,但到目前为止没有成功。我想代码的第一部分是问题所在,所以我只是添加了第二部分,以防它可能更有用。基本上,几天后,我的数据库停止工作,我不知道为什么。这是MongoDB的云版本,我使用NodeJs+ExpressJs+Mongoose。提前感谢您的每一个提示 0|app | at eachAsync (/home/redicerap/apps/nashinobi/backend/node_mod
0|app | at eachAsync (/home/redicerap/apps/nashinobi/backend/node_mod ules/mongodb/lib/core/utils.js:135:5)
0|app | at Pool.reset (/home/redicerap/apps/nashinobi/backend/node_mo dules/mongodb/lib/core/connection/pool.js:709:3)
0|app | at /home/redicerap/apps/nashinobi/backend/node_modules/mongod b/lib/core/sdam/monitoring.js:202:19
0|app | at /home/redicerap/apps/nashinobi/backend/node_modules/mongod b/lib/core/sdam/monitoring.js:164:18
0|app | at Server.command (/home/redicerap/apps/nashinobi/backend/nod e_modules/mongodb/lib/core/sdam/server.js:239:14)
0|app | at checkServer (/home/redicerap/apps/nashinobi/backend/node_m odules/mongodb/lib/core/sdam/monitoring.js:148:12)
0|app | at Object.monitorServer [as monitorFunction] (/home/redicerap /apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:193:3)
0|app | at Server.monitor (/home/redicerap/apps/nashinobi/backend/nod e_modules/mongodb/lib/core/sdam/server.js:216:12)
0|app | at Timeout.<anonymous> (/home/redicerap/apps/nashinobi/backen d/node_modules/mongodb/lib/core/sdam/topology.js:859:22)
0|app | at listOnTimeout (internal/timers.js:531:17) {
0|app | name: 'MongoError',
0|app | [Symbol(mongoErrorContextSymbol)]: {}
0|app | },
0|app | [Symbol(mongoErrorContextSymbol)]: {}
0|app | }
0|app | MongoTimeoutError: Server selection timed out after 30000 ms
0|app | at Timeout._onTimeout (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/topology.js:878:9)
0|app | at listOnTimeout (internal/timers.js:531:17)
0|app | at processTimers (internal/timers.js:475:7) {
0|app | name: 'MongoTimeoutError',
0|app | reason: MongoError: server instance pool was destroyed
0|app | at basicWriteValidations (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/server.js:408:12)
0|app | at basicReadValidations (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/server.js:415:17)
0|app | at Server.command (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/server.js:237:19)
0|app | at checkServer (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:148:12)
0|app | at /home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:204:7
0|app | at /home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/connection/pool.js:732:9
0|app | at eachAsync (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/utils.js:135:5)
0|app | at Pool.reset (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/connection/pool.js:709:3)
0|app | at /home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:202:19
0|app | at /home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:164:18
0|app | at Server.command (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/server.js:239:14)
0|app | at checkServer (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:148:12)
0|app | at Object.monitorServer [as monitorFunction] (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:193:3)
0|app | at Server.monitor (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/server.js:216:12)
0|app | at Timeout.<anonymous> (/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/topology.js:859:22)
0|app | at listOnTimeout (internal/timers.js:531:17) {
0|app | name: 'MongoError',
0|app | [Symbol(mongoErrorContextSymbol)]: {}
0|app | },
0|app | [Symbol(mongoErrorContextSymbol)]: {}
0|app | }
0 | app |在eachAsync(/home/redicerap/apps/nashinobi/backend/node|modules/mongodb/lib/core/utils.js:135:5)
0 | app | at Pool.reset(/home/redicerap/apps/nashinobi/backend/node|momodules/mongodb/lib/core/connection/Pool.js:709:3)
0 | app | at/home/redicerap/apps/nashinobi/backend/node|u modules/mongod b/lib/core/sdam/monitoring.js:202:19
0 | app | at/home/redicerap/apps/nashinobi/backend/node|u modules/mongod b/lib/core/sdam/monitoring.js:164:18
0 | app | at Server.command(/home/redicerap/apps/nashinobi/backend/nod e|u modules/mongodb/lib/core/sdam/Server.js:239:14)
checkServer上的0 | app |(/home/redicerap/apps/nashinobi/backend/node|m odules/mongodb/lib/core/sdam/monitoring.js:148:12)
0 | app | at Object.monitorServer[作为monitorFunction](/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:193:3)
0 | app | at Server.monitor(/home/redicerap/apps/nashinobi/backend/nod e|u modules/mongodb/lib/core/sdam/Server.js:216:12)
0 |应用程序|超时。(/home/redicerap/apps/nashinobi/backen d/node_modules/mongodb/lib/core/sdam/topology.js:859:22)
0 | app | at listOnTimeout(internal/timers.js:531:17){
0 |应用程序|名称:“MongoError”,
0 | app |[符号(mongoErrorContextSymbol)]:{}
0 | app |},
0 | app |[符号(mongoErrorContextSymbol)]:{}
0 | app |}
0 | app | MongoTimeOuter错误:服务器选择在30000毫秒后超时
0 | app |超时。|超时(/home/redicerap/apps/nashinobi/backend/node|modules/mongodb/lib/core/sdam/topology.js:878:9)
0 | app | at listOnTimeout(internal/timers.js:531:17)
0 | app | at processTimers(internal/timers.js:475:7){
0 |应用程序|名称:'MongoTimeoutError',
0 |应用程序|原因:MongoError:服务器实例池已销毁
0 | app |在基本验证中(/home/redicerap/apps/nashinobi/backend/node|modules/mongodb/lib/core/sdam/server.js:408:12)
0 | app |在BasicRevalidations(/home/redicerap/apps/nashinobi/backend/node|u modules/mongodb/lib/core/sdam/server.js:415:17)
0 | app | at Server.command(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/Server.js:237:19)
0 | app |位于checkServer(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:148:12)
0 | app | at/home/redicerap/apps/nashinobi/backend/node|u modules/mongodb/lib/core/sdam/monitoring.js:204:7
0 | app | at/home/redicerap/apps/nashinobi/backend/node|u modules/mongodb/lib/core/connection/pool.js:732:9
0 | app |在eachAsync(/home/redicerap/apps/nashinobi/backend/node|modules/mongodb/lib/core/utils.js:135:5)
0 | app | at Pool.reset(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/connection/Pool.js:709:3)
0 | app | at/home/redicerap/apps/nashinobi/backend/node|u modules/mongodb/lib/core/sdam/monitoring.js:202:19
0 | app | at/home/redicerap/apps/nashinobi/backend/node|u modules/mongodb/lib/core/sdam/monitoring.js:164:18
0 | app | at Server.command(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/Server.js:239:14)
0 | app |位于checkServer(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:148:12)
0 | app | at Object.monitorServer[作为monitorFunction](/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/monitoring.js:193:3)
0 | app |位于Server.monitor(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/Server.js:216:12)
0 | app |超时。(/home/redicerap/apps/nashinobi/backend/node_modules/mongodb/lib/core/sdam/topology.js:859:22)
0 | app | at listOnTimeout(internal/timers.js:531:17){
0 |应用程序|名称:“MongoError”,
0 | app |[符号(mongoErrorContextSymbol)]:{}
0 | app |},
0 | app |[符号(mongoErrorContextSymbol)]:{}
0 | app |}
解决方案非常简单。我在两个不同的地方返回了响应,因为我不喜欢猫鼬查询的嵌套。整个NodeJS后端因此崩溃,但很难发现,因为它很少发生,但经常发生。确保只返回一次res.status(200)或任何内容。在我分配给const的每个Mongoose查询中,我都返回了res.status(200),我认为这没问题,因为第二次返回甚至无法实现,大多数情况下都是这样。此错误与mongoose本身无关。检查mongo.close()@Girgetto我已经在此线程中找到了解决方案。我没有蒙哥牌的。“我只是在建立一种联系,就这样。”阿列克谢。这个问题有什么解决办法吗?我对mongodb 4.0也有同样的问题。1@NimeshaKalinga很抱歉这么晚才回复,但解决办法很简单。我在两个不同的地方返回了一个响应,因为我不喜欢mongo查询的嵌套。所以整个后端都因此崩溃了,但它