4
votes

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.

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.

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

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

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

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

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 ?

3
My Mongoose knowledge is not that extense, but, shouldn't be your URI something like mongodb://username:password@host:port/database?options...? Like mentioned in hereamport
Cannot use mongodb with Google App Engine standard environment, Datastore is the only option. If mongodb has to be used move to flexible environmentcheekujha
@Mangu this is not the connection uri, hence the different format. The connection uri I use indeed use the format you specified :)tomrcht
@cheekujha I see, thanks for the answer!tomrcht
@Mangu: Yes its possible on GCE. But not possible on GAEcheekujha

3 Answers

7
votes

I had to use the older version of the atlas url

enter image description here

1
votes

It works for me with older driver version url: enter image description here

0
votes

You don't have to use Datastore. You can connect to a mongoDB hosted outside of Google servers, there is some example code here. I would also like to refer you to this documentation on connecting to external databases from the Standard Environment. Making sure your firewalls are open is necessary (and you have already done that, so that's great). MongoDB Node.JS drivers are listed here, depending on the version you use, different reference documents are available with connection samples (all listed on that same link).