I am trying to connect a nodejs app running on GCP App Engine to Mongo Atlas but I am receiving network errors. I have set up VPC Peering and have enabled a Serverless VPC connector and added the vpc_access_connector property in the app yaml and have whitelisted the IP range of the connector within Atlas. The exact error that I am seeing is
> MongoNetworkError: failed to connect to server [testcluster-shard-00-00-fbyja.gcp.mongodb.net:27017] on first connect
> [MongoNetworkError: connection 4 to testcluster-shard-00-00-fbyja.gcp.mongodb.net:27017 closed]
and the code I have is
var express = require("express");
var app = express();
require('dotenv').config();
var cors = require('cors');
const BodyParser = require('body-parser');
const MongoClient = require("mongodb").MongoClient;
const ObjectId = require('mongodb').ObjectID;
const CONNECTION_URL = process.env.DB_CONNECTION;
app.use(cors());
app.use(BodyParser.json());
app.use(BodyParser.urlencoded({extended: true}));
var database, collection;
app.listen(process.env.PORT, () => {
MongoClient.connect(CONNECTION_URL, {useNewUrlParser: true}, (error, client) => {
if(error){
throw error;
}
database = client.db("test");
collection = database.collection("test");
})
});
+srv
or explicitly enables TLS/SSL – Joe