spring-data-mongodb @indexed doesn't work when multi-tenant collections

314 Views Asked by At

The project based on spring-data-mongodb use @indexed doesn't work when use the multi-tenant collections.The following is the code:

@Document(collection = "#{ @tenantProvider.getTenant()}activity")
@Data
public class Activity {
    @Id
    private String id;
    @Indexed
    private String activityId;
}
1

There are 1 best solutions below

1
On

If the collection definition is dynamic you of course have to make sure you're creating indexes manually as there's no way for us to determine all possible collections that might be affected.

Users usually go ahead and create those indexes manually using IndexOperations.