loopbackio / loopback-connector-mongodb

The official MongoDB connector for the LoopBack framework.
https://loopback.io/doc/en/lb4/MongoDB-connector
Other
187 stars 236 forks source link

Unable to connect to Replica Set or Sharded Cluster #663

Open jukkakilponen opened 2 years ago

jukkakilponen commented 2 years ago

Steps to reproduce

Have a mongodb connection string with multiple hosts and ports (Replica Set or Sharded Cluster) as in https://www.mongodb.com/docs/manual/reference/connection-string/. For example mongodb://mongos0.example.com:27017,mongos1.example.com:27017,mongos2.example.com:27017

Current Behavior

Cannot start the application. TypeError [ERR_INVALID_URL]: Invalid URL: mongodb://mongos0.example.com:27017,mongos1.example.com:27017,mongos2.example.com:27017

Expected Behavior

Should connect to database.

Additional information

Tested with 6.2.0. The problem seems to be the use of nodejs URL to parse the connection string. The URL does not support multiple hosts with port numbers. See https://github.com/whatwg/url/issues/398. Problem introduced in commit 1d8a84b.

Related Issues

dhmlau commented 2 years ago

@jukkakilponen, thanks for reporting. Would you like to raise a PR?

jaishirole commented 2 years ago

@dhmlau This bug should have a regression label. Our application is broken since upgrade of mongodb connector to 6.x! There have been security vulnerability fixes in 6.x, which we need but not at the expense of regressed behavior. If no one is looking into, I'll take out some time over weekend to fix this.

jaishirole commented 2 years ago

@dhmlau @achrinza Can you assign this issue to me? I've coded up a fix, working on unit tests and as soon as done, will raise a PR.

manarhusrieh commented 2 years ago

Any updates on this issue since we are also facing the same issue and we are not able to use SRV in our current deployment architecture

jaishirole commented 2 years ago

@manarhusrieh My PR has been awaiting merge. @achrinza could you please confirm who would be reviewing and merging the PR?

manarhusrieh commented 2 years ago

@jaishirole I think you will need to resolve conflicts in your PR and rebase again on the latest version

haidanghoang commented 2 years ago

Hi guys, Any update on this issue?

NurdinDev commented 1 year ago

I think the PR is close to being merged, but it needs some conflicts resolved by @jaishirole and final approval.

gian1200 commented 11 months ago

It's worth mentioning that 6.1.0 do not have this issue