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

Introduce spring.data.mongodb.protocol to allow the MongoDB protocol to be customized when not using spring.data.mongodb.uri #43851

Open
storyzero opened this issue Jan 16, 2025 · 2 comments
Labels
for: team-meeting An issue we'd like to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged

Comments

@storyzero
Copy link

https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/PropertiesMongoConnectionDetails.java#L51

I can't generate a connection string with mongodb+srv:// because PropertiesMongoConnectionDetails is hardcoded to use mongodb://
MongoProperties should be able to specify the protocol, and PropertiesMongoConnectionDetails should generate the connection string using the specified protocol.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 16, 2025
@wilkinsona
Copy link
Member

This is similar to #17215, but the proposal there was to inject the separate properties into the URI. This was rejected as it would be a breaking change that would prevent the URI being used to override any other settings. We can consider introducing a protocol property for those who prefer to use the separate properties. It would be ignored when spring.data.mongodb.uri is specified.

In the meantime, please note that you can specify mongodb+srv as the protocol but, to do so, you must use spring.data.mongodb.uri to provide all of the connection information. When configuring the URI you can reference other properties if you wish:

example.mongodb.username=alice
example.mongodb.password=secret
spring.data.mongodb.uri=mongodb+srv://${example.mongodb.username}:${example.mongodb.password}@mongo.example/testdb

@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Jan 16, 2025
@storyzero
Copy link
Author

@wilkinsona
Thank you for your response.
To elaborate more on my situation, I want to use spring-cloud-vault-config-databases to auto-configure spring.data.mongodb.username and password. For security reasons, it is mandatory. Similarly, using mongodb+srv is also mandatory.

The example you provided seems worth trying, but the approach I was considering until just now was to manually configure everything, from the connection string to MongoTemplate, without any auto-configuration, using Vault.

However, it's a bit unfortunate that mongodb+srv can't be used unless it's through the URI.

@wilkinsona wilkinsona changed the title spring-boot-autoconfigure not support mongo+srv uri Introduce spring.data.mongodb.protocol to allow the MongoDB protocol to be customized when not using spring.data.mongodb.uri Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-meeting An issue we'd like to discuss as a team to make progress status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants