dbgate icon indicating copy to clipboard operation
dbgate copied to clipboard

BUG: MongoDB srv connections dont work with SSH tunnel

Open nick22985 opened this issue 1 year ago • 2 comments

Describe the bug If you use a mongodb+srv:// database URL with a ssh tunnel. It will not use the ssh tunnel / the connection won't work due to an error saying that the connection can not have a port

MongoParseError: mongodb+srv URI cannot have port number
    at new l (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\plugins\dbgate-plugin-mongo\dist\backend.js:2:219887)
    at t.parseOptions (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\plugins\dbgate-plugin-mongo\dist\backend.js:2:488879)
    at new w (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\plugins\dbgate-plugin-mongo\dist\backend.js:2:578087)
    at Object.connect (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\plugins\dbgate-plugin-mongo\dist\backend.js:2:768701)
    at e.exports (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\api\dist\bundle.js:2:2217724)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async process.<anonymous> (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\api\dist\bundle.js:2:2170694)

To Reproduce Steps to reproduce the behavior:

  1. Create a connection
  2. change the connection type to mongodb
  3. click use database URL
  4. paste a mongodb+srv:// URL into the database url
  5. click on ssh tunnel
  6. Add host details.
  7. SSH authentication I used is key file with a valid key

Expected behavior Should connection to the ssh tunnel then connection to the mongodb

Version Information (please complete the following information):

  • OS: Windows 11
  • App Version 5.5.5
  • Install source Installer
  • Type - Application
  • Database engine: MongoDb

nick22985 avatar Oct 16 '24 01:10 nick22985

I tested it and it worked for me

What is your database URL?

I tsetd it with: mongodb://dbusr:dbpwd@localhost:27017/dbname

janproch avatar Oct 22 '24 13:10 janproch

I tested it and it worked for me

What is your database URL?

I tsetd it with: mongodb://dbusr:dbpwd@localhost:27017/dbname

Hey @janproch , Thank you for your time.

It has to be one hosted on mongo cloud they let you host a free database https://www.mongodb.com/

The URL looks something like the below one. mongodb+srv://user:[email protected]/?retryWrites=true&w=majority

Self hosted instance of mongo work with ssh tunnels it is specifically srv ones that don't

Kind Regards, Nick

nick22985 avatar Oct 22 '24 15:10 nick22985

Hey, This is still happening for me on Version: 6.3.0 Build date: 2025-03-18

MongoParseError: mongodb+srv URI cannot have port number
    at new ConnectionString (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\node_modules\mongodb\node_modules\mongodb-connection-string-url\lib\index.js:146:23)
    at parseOptions (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\node_modules\mongodb\lib\connection_string.js:203:17)
    at new MongoClient (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\node_modules\mongodb\lib\mongo_client.js:52:61)
    at Object.connect (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\plugins\dbgate-plugin-mongo\dist\backend.js:2:96332)
    at connectUtility (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\api\dist\bundle.js:2:1529807)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async process.<anonymous> (C:\Users\nick\AppData\Local\Programs\dbgate\resources\app.asar\packages\api\dist\bundle.js:2:1475398)

Error JSON: {}

Connection: {
  "engine": "mongo@dbgate-plugin-mongo",
  "useDatabaseUrl": "***",
  "databaseUrl": "***",
  "displayName": "***",
  "connectionColor": "***",
  "unsaved": false,
  "_id": "***",
  "parent": "***",
  "useSshTunnel": true,
  "sshHost": "***",
  "sshMode": "keyFile",
  "sshLogin": "***",
  "sshKeyfile": "***",
  "requestDbList": false
}

Regards, nick

nick22985 avatar Mar 31 '25 22:03 nick22985

@janproch could this be reopened if possible?

nick22985 avatar May 23 '25 05:05 nick22985