Cannot connect with mongo db (cf ssh) - MongoNetworkError

496 views Asked by At

I want to connect my local NodeJS app with the Swisscom Cloud Foundry MongoDB service instance. As I see in the service key, there are three ports for mongo db. So, I bind the ports with the cf ssh ports.

cf ssh -L 63307:kubernetes-service-node.service.consul:37268 {my binded app}
cf ssh -L 63308:kubernetes-service-node.service.consul:39279 {my binded app}
cf ssh -L 63309:kubernetes-service-node.service.consul:45817 {my binded app}

After successfully run cf ssh, I'm not able to connect to my MongoDB and get a network error (MongoNetworkError: failed to connect to server [kubernetes-service-node.service.consul:63308]) in NodeJS (mongoose connect with the dtabase_uri). Same behavior with MongoDB Compass client.

What I'm doing wrong?

1

There are 1 answers

3
Sandro Mathys On BEST ANSWER

Have you added a hosts entry on your system to resolve kubernetes-service-node.service.consul to 127.0.0.1?

Also, I think you don't need to open three SSH connections, i.e. I think you can specify several port forwardings in a single connection like this: cf ssh -L ... -L ... -L ... <app>