我在MongoDB Atlas中有一个MongoDB集群,我使用他们提供的此MONGO_URI连接到它。格式如下:
mongodb://<USERNAME>:<PASSWORD>@cluster0-shard-00-00-nnn.gcp.mongodb.net:27017,cluster0-shard-00-01-nnn.gcp.mongodb.net:27017,cluster0-shard-00-02-nnn.gcp.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
当我在本地运行node.js程序时,我可以读写数据库。但是,当我部署到Google Cloud时,已经连接到它了。这是我在Google控制台中看到的内容:
Mongoose connection "error" event fired with:
{ MongoError: connection 5 to cluster0-shard-00-02-32tq4.mongodb.net:27017 closed
at Function.MongoError.create (/srv/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:29:11)
at TLSSocket.<anonymous> (/srv/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:214:22)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at TLSSocket.emit (events.js:211:7)
at _handle.close (net.js:557:12)
at Socket.done (_tls_wrap.js:356:7)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at TCP._handle.close [as _onclose] (net.js:557:12)
我尝试将allow-mongodb
添加到防火墙,协议和端口为tcp:27017
,方向为ingress
,IP范围为0.0.0.0/0
,但仍无法正常工作。有人可以告诉我我在这里想念什么吗?
P.S我有点怀疑我也必须将mongodb群集的IP也添加到防火墙,尽管我不确定