On Heroku, I get the following error when my app starts:
2021-01-22T02:27:08.944544+00:00 app[web.1]: {"name":"dpt-server","hostname":"9c28c922-9c1d-4118-81f3-f8a4e7dafceb","pid":44,"level":50,"msg":"db error, can't connect failed to connect to server [testdpt-shard-00-01.wfj1w.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to testdpt-shard-00-01.wfj1w.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:356:9)
at Object.onceWrapper (events.js:421:26)
at TLSSocket.emit (events.js:314:20)
at net.js:675:12
at TCP.done (_tls_wrap.js:568:7) {
errorLabels: [Array],
[Symbol(mongoErrorContextSymbol)]: {}
}]","time":"2021-01-22T02:27:08.930Z","src":{"file":"/app/src/lib/mongoose.js","line":16},"v":0}
2021-01-22T02:27:08.945102+00:00 app[web.1]: [2021-01-22T02:27:08.930Z] ERROR: dpt-server/44 on 9c28c922-9c1d-4118-81f3-f8a4e7dafceb (/app/src/lib/mongoose.js:16):
2021-01-22T02:27:08.945105+00:00 app[web.1]: db error, can't connect failed to connect to server [testdpt-shard-00-01.wfj1w.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to testdpt-shard-00-01.wfj1w.mongodb.net:27017 closed
2021-01-22T02:27:08.945106+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:356:9)
2021-01-22T02:27:08.945107+00:00 app[web.1]: at Object.onceWrapper (events.js:421:26)
2021-01-22T02:27:08.945108+00:00 app[web.1]: at TLSSocket.emit (events.js:314:20)
2021-01-22T02:27:08.945109+00:00 app[web.1]: at net.js:675:12
2021-01-22T02:27:08.945109+00:00 app[web.1]: at TCP.done (_tls_wrap.js:568:7) {
2021-01-22T02:27:08.945109+00:00 app[web.1]: errorLabels: [Array],
2021-01-22T02:27:08.945110+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2021-01-22T02:27:08.945110+00:00 app[web.1]: }]
2021-01-22T02:27:08.950681+00:00 app[web.1]: [2021-01-22T02:27:08.930Z] ERROR: dpt-server/44 on 9c28c922-9c1d-4118-81f3-f8a4e7dafceb (/app/src/lib/mongoose.js:16):
2021-01-22T02:27:08.950685+00:00 app[web.1]: db error, can't connect failed to connect to server [testdpt-shard-00-01.wfj1w.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to testdpt-shard-00-01.wfj1w.mongodb.net:27017 closed
2021-01-22T02:27:08.950685+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connection.js:356:9)
2021-01-22T02:27:08.950686+00:00 app[web.1]: at Object.onceWrapper (events.js:421:26)
2021-01-22T02:27:08.950687+00:00 app[web.1]: at TLSSocket.emit (events.js:314:20)
2021-01-22T02:27:08.950688+00:00 app[web.1]: at net.js:675:12
2021-01-22T02:27:08.950688+00:00 app[web.1]: at TCP.done (_tls_wrap.js:568:7) {
2021-01-22T02:27:08.950689+00:00 app[web.1]: errorLabels: [Array],
2021-01-22T02:27:08.950689+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2021-01-22T02:27:08.950690+00:00 app[web.1]: }]
I've whitelisted 0.0.0.0/0 in Atlas, so it should be allowing all IPs. It runs fine locally. I've sifted through the MongoDB Atlas troubleshooting section for connections in great detail but I'm not sure where to go with this. Anyone have any idea what to make of this?
question from:
https://stackoverflow.com/questions/65838775/node-js-app-on-heroku-unable-to-connect-to-mongodb-atlas-whitelisted-all-ips-w 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…