从Postman向Heroku发送请求会返回503和/或UnknownReplWriteConcern [英] Sending requests from Postman to Heroku returns 503 and/or UnknownReplWriteConcern

查看:557
本文介绍了从Postman向Heroku发送请求会返回503和/或UnknownReplWriteConcern的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将邮递员的发帖请求发送到Heroku应用程序,但它会不断返回带有code = H12503 status error.该应用程序可以在本地主机上正常工作.

I am trying to send a post request from Postman to a Heroku app but it keeps returning a 503 status error with code = H12. The app works fine in localhost.

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

With regards to the database, I have a cluster (M0) in Atlas and I am using the same non-srv connection string that I am using to connect Compass to the same cluster in Atlas.

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

The only error I see when I run heroku logs is:

//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.

But I have already added 0.0.0.0/0 in Atlas's IP whitelist.

什么可能导致此错误?

推荐答案

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

So with the help and assistance of the MongoDB Atlas support team, I managed to fix this by simply using the srv version of the connection string that I got from Atlas to connect with Heroku. After switching the connection string to the srv version, postman was able to make requests without getting the 503 error.

srv版本看起来像这样:

The srv version looks something like this:

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

但是,MongoDB Compass(v1.21.2)似乎无法与srv版本的连接字符串连接,因此我不得不继续使用Compass的非srv版本,如下所示:

However, MongoDB Compass (v1.21.2) cannot seem to connect with the srv version connection string so I had to continue using the non-srv version for Compass which looks something like this:

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的数​​据,总是出现以下错误:


One issue that I noticed with the current srv version connection string above (which might be happening just for me though so skip this step if the current srv version connection string works fine for you) was that even though it seems to be adding the data that I'm sending from postman to Atlas, I always get the following error:

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

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

So with the advise of the MongoDB Atlas support team, I just remove w=majority from the connection string and that seems to fix that issue.

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

这篇关于从Postman向Heroku发送请求会返回503和/或UnknownReplWriteConcern的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆