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

Mongodb host: cannot use hostname without port #2219

Closed
SavvasMohito opened this issue Feb 20, 2023 · 4 comments
Closed

Mongodb host: cannot use hostname without port #2219

SavvasMohito opened this issue Feb 20, 2023 · 4 comments
Milestone

Comments

@SavvasMohito
Copy link
Contributor

Hello there. I have been using and really enjoying cygnus. While transferring my docker-compose project to a Kubernetes cluster, I came across a problem:

Cygnus accepts MongoDB hosts only when a port is specified (here). This is an issue in my case, where I am using a Kubernetes service for reaching my MongoDB pod, and I only have a hostname (which includes both the IP and Port of the target MongoDB pod). For example, the kubernetes service hostname can be something like "mongodb-service".

I have made a custom image of cygnus to make it work in my case, by replacing the above highlighted code with this:

servers.add(new ServerAddress(uri));

where uri = the kubernetes service name I provided, and it works.

I understand the need to check the given MongoDB URL but I believe this should be implemented differently and not by checking wether a port has been provided or not. You can, for example, try if the connection works with any given URL (with port or not) directly to MongoDB endpoint. I may have a look into that myself and create a pull request if I manage to make it work. Thanks.

@cesarjorgemartinez
Copy link
Contributor

cesarjorgemartinez commented Feb 20, 2023

You are correct, in the sense that the port in all cases is optional according to the MongoDB documentation (with the default value 27017...). All cases the port is optional.

Furthermore, could you test that the mongodb+srv DNS connection type works?

Reference:
https://www.mongodb.com/docs/manual/reference/connection-string/

@fgalan
Copy link
Member

fgalan commented Feb 21, 2023

I may have a look into that myself and create a pull request if I manage to make it work

Thanks for your willingness to work on this! :)

We would be more than happy to review and eventually merge that pull request!

@SavvasMohito
Copy link
Contributor Author

We would be more than happy to review and eventually merge that pull request!

Hello again, yesterday I opened a pull request with my suggested commit. Let me know if it works out. :)

@fgalan fgalan added this to the 3.0.0 milestone Mar 1, 2023
@fgalan
Copy link
Member

fgalan commented Mar 1, 2023

Having merged PR #2221, this issue can now be closed.

@SavvasMohito thanks for the contribution! :)

@fgalan fgalan closed this as completed Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants