egg-cnode
egg-cnode copied to clipboard
mongodb没有重连机制
当docker挂掉了,egg-cnode也挂掉了,当你重启了docker,egg-cnode依然是挂掉的
2018-06-25 13:37:44,233 ERROR 33312 [-/127.0.0.1/-/1ms GET /] nodejs.MongoError: Topology was destroyed
at nextFunction (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb-core/lib/cursor.js:547:27)
at Cursor.next [as _next] (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb-core/lib/cursor.js:701:3)
at fetchDocs (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb/lib/cursor.js:857:10)
at toArray (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb/lib/cursor.js:884:3)
at Cursor.toArray (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb/lib/cursor.js:837:44)
at /Users/i5ting/workspace/github/egg-cnode/node_modules/mquery/lib/collection/node.js:30:14
at handleCallback (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb/lib/utils.js:120:56)
at Collection.find (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongodb/lib/collection.js:384:44)
at NativeCollection.(anonymous function) [as find] (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:130:28)
at NodeCollection.find (/Users/i5ting/workspace/github/egg-cnode/node_modules/mquery/lib/collection/node.js:26:19)
at model.Query.Query._find (/Users/i5ting/workspace/github/egg-cnode/node_modules/mongoose/lib/query.js:1353:27)
at /Users/i5ting/workspace/github/egg-cnode/node_modules/kareem/index.js:250:8
at /Users/i5ting/workspace/github/egg-cnode/node_modules/kareem/index.js:23:7
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
name: 'MongoError'
message: 'Topology was destroyed'
pid: 33312
hostname: MacBook-Pro-5.local
^C2018-06-25 13:38:18,852 INFO 33310 [master] receive signal SIGINT, closing
把下面配置加上,会好一些
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
参见 http://mongoosejs.com/docs/connections.html#options
PR welcome.