Connect to mongodb / documentdb throught ssh tunnel
See original GitHub issueDo 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:
- Created 2 years ago
- Comments:14
I resolved the problem.
Need to add this parameter in connection string - “&directConnection=true”. And add some parameters to tunnel connection:
@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!