Proxy to MongoDB Atlas timesout

Not applicable

I am trying to connect to my MongoDB Atlas cluster to run a query and return the results as an API through Edge.

I have used the NodeJS client for MongoDB locally and successfully connected to my cluster and run a query. So I know the cluster is running and can be connected to.

I wondered if it was the port 27017 causing issues?

I have enabled access to MongoDB Atlas on 0.0.0.0/0 so its not an IP Whitelist issuse

Can anyone advice me on how to do this? - thanks

var uri = "mongodb://user:password@cluster_etc:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin";
MongoClient.connect(uri, function(err, db) {
 if (err) throw err;
 console.log(">> Connected to Database");

});
2 5 3,140
5 REPLIES 5

Hi Tim.

I haven't connected to Mongo specifically but I have built API Proxies that run inside Apigee Edge, using nodejs, and connect to external data sources like:

  • postgres
  • MS SQL Server
  • LDAP systems
  • others

These things use various ports. Therefore I doubt that it is a port issue. You wrote:

I have used the NodeJS client for MongoDB locally and successfully connected to my cluster and run a query. So I know the cluster is running and can be connected to.

yes, you have proven that the Mongo server is running and listening, and that your local machine has connectivity to it. But this does not prove that the mongo server is accessible from the internet, which is where the Apigee API Proxies run. I read what you wrote about 0.0.0.0/0 and that you believe it's not an IP whitelist issue. But there are also other possibilities - the IP restriction may be enforced by some other system that sits between Apigee and your Mongo server.

As an example, servers running on my own desktop machine cannot be contacted by systems on the internet. A firewall managed by the corporate IT team prevents the inbound connection, regardless what I have set my ip whitelist to, locally. I have no control over that.

To determine if a network connectivity issue is causing the timeout, you'd need to use an arbitrary machine running in AWS or GCP or Azure or somewhere on the open internet, and connect to the mongo server. a simple connection with telnet to port 27017 would be fine... you don't need to actually run a mongo client to prove the connectivity, though connecting with a mongo client would also prove connectivity obviously. If you can connect from the internet, then the timeout is something specific to Apigee. If you cannot connect from the internet, then I suspect a network configuration issue is preventing communication.

Once nice option might be to use Google App Engine - you can host nodejs apps there, and maybe your code will run unchanged. If you can connect from THERE, then ... it's an Apigee issue.

It is possible that the Apigee version of nodejs (running in Trireme) is the source of the problem. As you may know, the nodejs logic that you can currently embed into an API PRoxy in Apigee Edge does not run in v8 node, but rather a JVM-hosted Javascript engine called Trireme. There are some differences, and probably the people who build the Mongo client do not test their client library on Trireme.

If you wanted to be thorough, you could test your code outside of Apigee Edge, but still in trireme. For example, you could run trireme on your local machine. Find Trireme on github.

HTH

Hi Dino

I tested my MongoDB Atlas from an AWS Lambda function and it can connect. So I installed Trireme using NPM and then run my index.js script. That timesout.

So it seems it is definitely something to do with Trireme and the mongodb client.

I am going to try a different client like Mongoose and see if that works

Thanks for your help

Tim

Not applicable

Hey Tim,

Don't know what the problem is. It might be possible that it's on Trireme as Dino mentioned. However, can you use other mongoDB provider? I tried mongoDB Atlas and it's pretty cool! It sounds very similar to mLab, which I found on this GCP Tutorial. https://cloud.google.com/nodejs/resources/databases/mongodb

Could you try this one and post your results? I'll try to test tomorrow or later this week with an actual Node.js API Proxy.

Hope it helps!

Hi Diego

I have launched an mLab and loaded some data, created a new a127 Proxy and am getting an Authentication failed error. This is using the offical MongoDB NodeJS client and using a127 to deploy the app.

I am going to try and see if I can try and create a proxy NodeJS without using a127.

thanks


Tim

Sounds good. Willtry it on my end too.