In a post last august sbzoom proposed a solution to make spring-data-mongoDB multi-tenant:
\"You have to make your own RepositoryFactoryBean. Here is the example fro
I had a similar approach to Oliver Gierke. At least on database-level. https://github.com/Loki-Afro/multi-tenant-spring-mongodb You should be able to do things like this:
MultiTenantMongoDbFactory.setDatabaseNameForCurrentThread("test");
this.personRepository.save(createPerson("Phillip", "Wirth", ChronoUnit.YEARS.between(
LocalDate.of(1992, Month.FEBRUARY, 3),
LocalDate.now())));
System.out.println("data from test: " + this.personRepository.findAll());
// okay? fine. - lets switch the database
MultiTenantMongoDbFactory.setDatabaseNameForCurrentThread("test666");
// should be empty
System.out.println("data from test666: " + this.personRepository.findAll());