question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce AbstractRoutingMongoDatabaseFactory

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, Apr 26, 2021

Since this never was a priority this ticket has to line up in the queue. For now, the workaround would be to not use @Transactional infrastructure but rather make use of the programmatic ClientSession API on MongoTemplate.withSession(…) where you control the session lifecycle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Guide to Spring AbstractRoutingDatasource - Baeldung
In this quick article, we'll look at Spring's AbstractRoutingDatasource as a way of dynamically determining the actual DataSource based on ...
Read more >
Spring Data MongoDB - Reference Documentation
This section provides some basic introduction to Spring and Document databases. ... The central interface in the Spring Data repository abstraction is ...
Read more >
Dynamic Data Source Routing in Spring Boot using ...
AbstractRoutingDataSource is an abstract DataSource implementation that routes getConnection() calls to one of various target DataSources ...
Read more >
org.springframework.data.mongodb.core ... - Tabnine
Simple PersistenceExceptionTranslator for Mongo. Convert the given runtime exception to an appropriate exception from the org.springframework.dao hierarchy.
Read more >
spring-projects/spring-data - Gitter
as a result of executing simple delete query DELETE FROM my_table WHERE ... but if the auditing functionality doesn't abstract away this complexity, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found