Can't connect from AppEngine to Atlas free


I’m having problems connecting from AppEngine Free Tier to Atlas Free Tier, using node.js. I’m setting access to 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 [] on first connect [MongoNetworkError: connection 3 to closed


    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 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 {
      '' => [ServerDescription],
      '' => [ServerDescription],
      '' => [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.