Add MongoClientSettingsBuilderCustomizer hook for the Mongo client#15716
Merged
codeconsole merged 1 commit intoJun 5, 2026
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
|
@codeconsole Can this target 8? |
Contributor
Author
@matrei done, how about a review ;P |
sbglasius
approved these changes
Jun 5, 2026
jdaugherty
approved these changes
Jun 5, 2026
Allow application beans to customize the MongoClientSettings.Builder before the MongoClient is created for the default connection source. This is the supported extension point for settings with no grails.mongodb.* equivalent — e.g. registering a driver CommandListener for metrics/tracing, tuning the connection pool, or configuring read/write concerns programmatically. Any MongoClientSettingsBuilderCustomizer beans in the context are injected into MongoConnectionSourceFactory (registered with autowire) and applied, in order, in create(). Mirrors Spring Boot's interface of the same name.
ef4d76c to
d37eba7
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #15716 +/- ##
==================================================
- Coverage 48.3729% 48.3694% -0.0035%
- Complexity 15108 15109 +1
==================================================
Files 1870 1870
Lines 85457 85459 +2
Branches 14900 14901 +1
==================================================
- Hits 41338 41336 -2
- Misses 37784 37785 +1
- Partials 6335 6338 +3
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
MongoClientSettingsBuilderCustomizerextension point to GORM for MongoDB. Any beans of this type in the application context are applied, in order, to theMongoClientSettings.Builderof the default connection source before theMongoClientis created.Why
There is currently no supported way to customize
MongoClientSettingsfor things that have nograils.mongodb.*configuration equivalent — most notably registering a drivercom.mongodb.event.CommandListenerfor metrics/tracing (e.g. Micrometer'sMongoMetricsCommandListener), but also programmatic connection-pool tuning, read/write concerns, etc. Today that requires replacing the datastore wiring.Mirrors Spring Boot's
MongoClientSettingsBuilderCustomizerof the same name, giving GORM-MongoDB users the same ergonomics.How
org.grails.datastore.mapping.mongo.connections.MongoClientSettingsBuilderCustomizer.MongoConnectionSourceFactorygains an@Autowired(required = false) List<MongoClientSettingsBuilderCustomizer>applied increate()just beforeMongoClients.create(...). The factory is already registered withbean.autowire = trueinMongoDbDataStoreSpringInitializer, so customizer beans are injected automatically. No behavior change when none are defined.Example
Tests
Added to
MongoConnectionSourceFactorySpec: