Can't connect from AppEngine to Atlas free

Hi,

I’m having problems connecting from AppEngine Free Tier to Atlas Free Tier, using node.js. I’m setting access to 0.0.0.0/0 as this is just a test project.

First up, is it even possible? It works fine on my local node server, but uploading to GAE I get the following error:

MongoNetworkError: failed to connect to server [cluster0-shard-00-02.pntaf.mongodb.net:27017] on first connect [MongoNetworkError: connection 3 to cluster0-shard-00-02.pntaf.mongodb.net:27017 closed

Code:

    var db;
    MongoClient.connect(connectionString, (err, database) => {
      if (err) return console.log("Connect error: ", err);
      db = database;
      app.listen(port, () => {
        console.log("listening on " + port);
      });
    });

Thanks for any help!

Trying various things, but always unable to connect. I’m now using App Engine Flex, as i’ve read Standard isn’t capable (but no other explanation as to why).

MongoServerSelectionError: connection <monitor> to 35.224.187.131:27017 closed
    at Timeout._onTimeout (/app/node_modules/mongodb/lib/core/sdam/topology.js:438:30)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: 'atlas-loe0la-shard-0',
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster0-shard-00-00.pntaf.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-01.pntaf.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-02.pntaf.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: 30,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: 9
  }
}

Bit of an update: As far as I can tell, it’s not possible to allow traffic on port 27017 on AppEngine?

Instead, I set up a Bitnami node.js stack on Compute Engine, set firewall rules for 27017 on Google VPC network, opened the port on the server, and set MongoDB Atlas network access to the server’s IP. This now works.

I’d really like to know if I’m wrong about AppEngine and MongoDB Atlas, as I’d much prefer to use it.