我在由kubernetes管理的google计算引擎上运行nodejs api作为pod。 API很好地连接到数据库,但它突然失败,显示此错误:
listening to http server on 0.0.0.0:8080...
events.js:160
throw er; // Unhandled 'error' event
^
MongoError: failed to connect to server [mongo:27017] on first connect [MongoError: getaddrinfo ENOTFOUND mongo mongo:27017]
at Pool.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/topologies/server.js:328:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/pool.js:274:12)
at Connection.g (events.js:292:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/connection.js:177:49)
at Socket.g (events.js:292:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at connectErrorNT (net.js:1021:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
我尝试重启prods,删除并重新创建容器但没有成功?
这就是我连接数据库的方式:
mongoose.connect(process.env.MONGO_DEV_URL || process.env.MONGODB_URI || 'mongodb://mongo:27017:yaxiDb/yaxiDb', { useMongoClient: true });
如何调试此问题,可能出现问题?
答案 0 :(得分:0)
我刚刚找到了解决方案,创建服务的顺序很重要。我删除了使用该数据库的所有服务并重新创建它们:
Resources