question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connect to mongodb / documentdb throught ssh tunnel

See original GitHub issue

Do you want to request a feature or report a bug? bug

What is the current behavior?

I am getting connection timeout when create connection throught ssh tunnel:

MongooseServerSelectionError: Server selection timed out after 30000 ms at NativeConnection.Connection.openUri (/Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/node_modules/mongoose/lib/connection.js:797:32) at /Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/node_modules/mongoose/lib/index.js:332:10 at /Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 at new Promise (<anonymous>) at promiseOrCallback (/Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (/Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/node_modules/mongoose/lib/index.js:1158:10) at Mongoose.connect (/Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/node_modules/mongoose/lib/index.js:331:20) at /Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/configuration/mongo.ts:32:27 at Generator.next (<anonymous>) at /Users/daviddakhovich/Documents/Projects/Bloxtax/bloxtax3/configuration/mongo.ts:8:71 { reason: TopologyDescription { type: 'ReplicaSetNoPrimary', servers: Map(1) { 'bloxtax-dev.co2kajlocir5.eu-west-1.docdb.amazonaws.com:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: 'rs0', commonWireVersion: 7, logicalSessionTimeoutMinutes: undefined } }

What is the expected behavior? It should not throw error cos connection exists and it works with mongoose 5.13.3 for example

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. Node - 16.13.0 Mongoose - 6.1.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14

github_iconTop GitHub Comments

11reactions
shadoworioncommented, Feb 23, 2022

@Code42Cate more data would be helpful, we haven’t been able to repro this.

I resolved the problem.

Need to add this parameter in connection string - “&directConnection=true”. And add some parameters to tunnel connection:

ssh -N -i key.pem -L localhost:27017:example.eu-west-1.docdb.amazonaws.com:27017 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -o ServerAliveInterval=15 -p 22 ubuntu@server.eu-west-1.compute.amazonaws.com
0reactions
toveruxcommented, Jul 22, 2022

@shadoworion Thanks god, I’ve been blocked on this problem for hours. Had the same use case of a connection over a SSH tunnel, MongoDB clients worked but not mongoose. Simply adding this fragment in the connection string made it work. Thank you very much for sharing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connecting to an Amazon DocumentDB Cluster from Outside ...
Use SSH tunneling to connect to an Amazon DocumentDB cluster. ... Amazon DocumentDB (with MongoDB compatibility) clusters are deployed within an Amazon ...
Read more >
Python SSH tunnel into EC2 and connect to DocumentDB
I am using the ssh_pymongo module, which wraps SSHTunnelForwarder. I am able to SSH directly into the EC2 instance and connect to the...
Read more >
Connecting to AWS DocumentDB - NoSQL Manager
However, you can use SSH tunneling (also known as “port forwarding”) to access your Amazon DocumentDB from NoSQL Manager for MongoDB.
Read more >
Proxy / SSH Tunnel Connection Tab — MongoDB Compass
The Proxy / SSH Tunnel tab allows you to connect to your deployment using a Proxy method or SSH Tunnel. Procedure. 1. Click...
Read more >
Connection to AWS DocumentDB through SSH tunnel
Create new connection to AWS DocumentDB using MongoDB driver option · Use SSH tunnel with "Key pair" auth type and .pem key. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found