The collection name is basically determined in BasicMongoPersistentEntity.getCollectionName(). This method is called whenever we have to decide which collection to interact with. The implementation uses a SpEL expression parser to evaluate the configured String as it might contain an EL expression. So here's how you can achieve what you want:
1. Create a Spring Bean do implement the logic to determine the customer specific part
Code:
@Component("customer")
class CollectionNameStrategy {
String part() {
// implement here
}
}
3. Configure a SpEL expression inside the @Document annotation
Code:
@Document("#{@customer.part() + '.accounts'}"
class Accounts {
}
@customer refers to the Spring bean named "customer" above and will call the part() method for each evaluation.