从 Postman 向 Heroku 发送请求 returns 503 and/or UnknownReplWriteConcern

Sending requests from Postman to Heroku returns 503 and/or UnknownReplWriteConcern

我正在尝试从 Postman 向 Heroku 应用程序发送 post 请求,但它一直返回 503 status errorcode = H12。该应用程序在本地主机上运行良好。

关于数据库,我在 Atlas 中有一个集群 (M0),我使用相同的非 srv 连接字符串将 Compass 连接到 Atlas 中的同一集群。

我在 运行 heroku logs 时看到的唯一错误是:

//single line broken into four lines for readability

UnhandledPromiseRejectionWarning:
MongooseServerSelectionError:
Could not connect to any servers in your MongoDB Atlas cluster.
One common reason is that you're trying to access the database from an IP that isn't whitelisted.

但是我已经在Atlas的IP白名单中添加了0.0.0.0/0


什么可能导致此错误?

因此,在 MongoDB Atlas 支持团队的帮助和协助下,我设法通过简单地使用从 Atlas 获得的连接字符串的 srv 版本来连接 Heroku 来解决此问题。将连接字符串切换到 srv 版本后,邮递员能够发出请求而不会出现 503 错误。

srv 版本看起来像这样:

mongodb+srv://someClusterAdmin:somePassword@someCluster.vwieg.mongodb.net/someName?retryWrites=true&w=majority

但是,MongoDB Compass (v1.21.2) 似乎无法连接 srv 版本的连接字符串,所以我不得不继续使用 Compass 的非 srv 版本,它看起来像这样:

mongodb://someClusterAdmin:somePassword@someCluster-shard-00-00.vwieg.mongodb.net:27017,someCluster-shard-00-01.vwieg.mongodb.net:27017,someCluster-shard-00-02.vwieg.mongodb.net:27017/someName?authSource=admin

我在上面的当前 srv 版本连接字符串中注意到的一个问题(这可能只发生在我身上,所以如果当前 srv 版本连接字符串对您来说工作正常,请跳过此步骤)是即使它看起来添加我从邮递员发送到 Atlas 的数据时,我总是收到以下错误:

"code": 79,
"codeName": "UnknownReplWriteConcern",
//some other lines

因此,在 MongoDB Atlas 支持团队的建议下,我只是从连接字符串中删除了 w=majority,这似乎解决了这个问题。

// &w=majority removed
mongodb+srv://someClusterAdmin:somePassword@someCluster.vwieg.mongodb.net/someName?retryWrites=true