spring-projects / spring-projects/spring-data-mongodb
Introduce AbstractRoutingMongoDatabaseFactory
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Hello maintainers!
I am currently using Spring Data MongoDB in a multi-tenant environment. To give a little context, as a security requirement from our customers, we need to have a different credential set for every tenant, which forces us to have multiple instances of MongoClient.
We managed to make this work by overriding the method doGetMongoDatabase from SimpleMongoClientDatabaseFactory, which I believe the way people usually do it. However, we're facing a really big issue with this way of doing thing: since we have multi instances of MongoClient, using @Transactional doesn't work properly. We end up with this error
java.lang.IllegalStateException: state should be: ClientSession from same MongoClient
Would you happen to have a fix for that? Or is it in your roadmap to offer an official support for multi-tenancy?
Thank you for your help!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with SimpleMongoClientDatabaseFactory and its doGetMongoDatabase method, then trace how @Transactional obtains MongoDB sessions. The requested outcome is an official AbstractRoutingMongoDatabaseFactory that supports multiple MongoClient instances for tenant-specific credentials without the ClientSession mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mongodb, spring
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100