New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect to mongodb / documentdb throught ssh tunnel #11105
Comments
Could you provide a script? |
Open tunnel throught the terminal: ssh -i "key.pem" -L 27017:bloxtax-dev.co2kajlocir5.eu-west-1.docdb.amazonaws.com:27017 ubuntu@ec2-34-229-221-164.compute-1.amazonaws.com -N Connection script to database: import Mongoose from "mongoose";
export const mongoConnect = async () => {
const uri = "mongodb://username:password@localhost:27017/test?retryWrites=false";
return await Mongoose.connect(uri, {
ssl: true,
sslValidate: false,
autoIndex: true,
connectTimeoutMS: 100000,
keepAlive: true,
})
.then(() => {
console.log("MongoDB Connected!");
return true;
})
.catch((err) => {
console.log("MongoDB isn't connected!", err);
return false;
});
}; |
try lowercase mongoose => |
No, nothing of that |
Can you connect without the ssh tunnel, if you're connecting from a machine that's whitelisted? |
Yes, It works without tunnel |
Can you print out what Also worth noting - Mongoose does not officially support documentdb. We answer questions and fix documentdb related bugs where possible, but we don't run tests against documentdb so there may be compatibility issues. |
Sorry for the late answer: Map(1) {
'bloxtax-dev.co2kajlocir5.eu-west-1.docdb.amazonaws.com:27017' => ServerDescription {
_hostAddress: new HostAddress('bloxtax-dev.co2kajlocir5.eu-west-1.docdb.amazonaws.com:27017'),
address: 'bloxtax-dev.co2kajlocir5.eu-west-1.docdb.amazonaws.com:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 1542349,
lastWriteDate: 0
}
} I understand that mongoose does not officially support documentdb, but it worked in previous major release 5.* correctly - so it's strange |
The only thing that this error message tells us is that Mongoose can't reach "bloxtax-dev.co2kajlocir5.eu-west-1.docdb.amazonaws.com:27017". Are you able to connect using the MongoDB shell via the ssh tunnel? |
Yes, I can connect using MongoDB shell, MongoDB Compass, Dbeaver, Mongoose 5.13.13 via ssh tunnel. |
I have the exact same setup and issue, downgrading mongoose to 5.13.8 fixed it for me. Happy to provide more debug data if needed |
@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". 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 |
@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! |
about 6 hours in the 🚽 until I found this. Thanks for the help @shadoworion . In my case, |
@pdemro how to solved it ? can u tell me more detail please ? i'm try to connect with documentdb and nestjs in localhost |
I am using mongoose version "^8.0.2" I am not able to connect to DocumentDB although i am able to connect with the same through mongo shell, compass. G3etting this error: Failed to connect with Mongo DB MongooseServerSelectionError: connect ETIMEDOU |
@rakshitweb please open a new issue and follow the issue template. It is worth noting that mongoose doesn't officially support documentdb, but we will try to resolve your issue if we can |
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
The text was updated successfully, but these errors were encountered: