从Google App Engine连接到MongoDB Atlas [英] Connect to MongoDB Atlas from Google App Engine

查看:123
本文介绍了从Google App Engine连接到MongoDB Atlas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google App Engine标准环境上设置API,但是在连接到遥远的MongoDB实例时遇到问题.

I'm trying to set up an API on the Google App Engine standard environment but I'm having trouble connecting to a distant MongoDB instance.

我在MongoDB Atlas上使用了一个免费的M0集群,所有IP都被列入了白名单. Google App Engine防火墙规则允许来自所有IP地址的所有流量,以确保连接请求未被阻止.

I use a free M0 cluster on MongoDB Atlas, all IP are whitelisted. The Google App Engine firewall rules allow all traffic from all IP addresses to make sure the connection request is not blocked.

但是,我无法连接到我的Mongo实例,并且出现以下错误:

However, I cannot connect to my Mongo instance and I get the following error:

ERROR db_connection querySrv ESERVFAIL <mongo-url>.gcp.mongodb.net

要连接到MongoDB实例,请使用Mongoose并执行以下操作:

To connect to the MongoDB instance I use Mongoose and do the following:

const db = await mongoose.connect(uri, { useNewUrlParser: true });

但是,由于我无法连接,db始终为null.是否可以通过App Engine Standard连接到MongoDB Atlas,还是必须使用Cloud Datastore?

However db will always be null since I cannot connect. Is there a way to connect to MongoDB Atlas from App Engine Standard or do I have to use Cloud Datastore ?

推荐答案

我必须使用旧版的Atlas网址

I had to use the older version of the atlas url

这篇关于从Google App Engine连接到MongoDB Atlas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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