Remote connect from SSH to mongodb private service

Hi, I connected to a private MongoDB service via SSH from my local laptop. How can I now connect to the database so that I can work with it locally in developer mode and also make it available for a Node.js project? Private serive mongodb can’t work like a cloud atlas, i need common database for my project?

Server no response tunnel

const forwardConfig = {
  srcHost: "127.0.0.1",
  srcPort: 27017,
  dstHost: "wowfiremaw-mongodb",
  dstPort: 27017,
};
 sshClient.forwardOut(
      forwardConfig.srcHost,
      forwardConfig.srcPort,
      forwardConfig.dstHost,
      forwardConfig.dstPort,

Hi,

If you’re able to SSH ot the instance, you’ll probably be able to SSH tunnel from your local machine to it to access it, e.g.

ssh -L <local_machine_port>:localhost:<mongodb_port> <ssh_connection> -N

So maybe something like:

ssh -L 27017:localhost:27017 srv-xxxxxxxxxxxxxxxxxx@ssh.oregon.render.com -N

Once the command was running, 127.0.0.1:27017 on your local machine would tunnel to the Private Service making calls to localhost:27017 on the instance.

However, it is usually a better practice to have a datastore instance per environment, so that local/developmental changes don’t affect deployed/production instances, but how you use your service would be up to you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.