Discriminator based multi-tenancy with Spring Data MongoDB

Viewed 329

There is a shared database that has a discriminator field "customer_id" in each collection. That is an approach that was taken for multi-tenancy support.

What would be the recommended approaches on how to implement support of the discriminator field in the latest Spring Data MongoDB?

The most straightforward way I can see at this point is to set "customer_id" in the ThreadLocal per each request (The data is exposed via REST API) and then just pass to each Spring Data method

findByXxxAndCustomerId(x, ThreadLocal.getCustomerId()) 
0 Answers
Related