Skip to content
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

Error when using MongoDB URL with replicas #310

Open
dottgonzo opened this issue Jan 12, 2022 · 2 comments
Open

Error when using MongoDB URL with replicas #310

dottgonzo opened this issue Jan 12, 2022 · 2 comments

Comments

@dottgonzo
Copy link

🐞 Describe the bug

i'm using my default connection to my replicated instance of mongo db. The url is:

mongodb://USERNAME:PASSWORD@MONGO1_URL:27017,MONGO2_URL:27017,MONGO3_URL:27017/ackee?authSource=admin&authMechanism=SCRAM-SHA-1

with MONGO1_URL, MONGO2_URL, MONGO3_URL fql names of the mongodb servers (that is currently used from many apps as mongodb uri),

but when the container start, it crash with:

TypeError [ERR_INVALID_URL]: Invalid URL: ........

and the error shows the desidered uri

it seems a valid url, accepted from mongodb spec, what is wrong? it seems an issue

the mongodb spec is:

mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
@dottgonzo dottgonzo added the bug label Jan 12, 2022
@dottgonzo
Copy link
Author

seems that if use the same URI removing ports it works, so:

mongodb://USERNAME:PASSWORD@MONGO1_URL,MONGO2_URL,MONGO3_URL/ackee?authSource=admin&authMechanism=SCRAM-SHA-1

instead of

mongodb://USERNAME:PASSWORD@MONGO1_URL:27017,MONGO2_URL:27017,MONGO3_URL:27017/ackee?authSource=admin&authMechanism=SCRAM-SHA-1

but the ports are allowed on mongodb specs, so it remain a bug

@electerious
Copy link
Owner

Found the problem. Ackee passes the URL to mongoose.connect so it theoretically supports this type of URL, but there's a stripUrlAuth function that removes the username and password from the URL before logging it to the console and this function can't deal with multiple URLs. See https://github.com/electerious/Ackee/blob/master/src/index.js#L19

A PR is welcome!

@electerious electerious changed the title invalid mongodb URL Error when using MongoDB URL with replicas Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants