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

查看:21
本文介绍了从 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 .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 将始终为空,因为我无法连接.有没有办法从 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 ?

推荐答案

我不得不使用旧版本的图集网址

I had to use the older version of the atlas url

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

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