像這樣的東西應該工作:
public class PerSchoolStudentRepository {
public static CrudRepository<Student, ObjectId> buildRepository(String school, MongoOperations mongoOperations) {
MongoPersistentEntity<Student> persistentEntity = (MongoPersistentEntity<Student>) mongoOperations.getConverter().getMappingContext().getPersistentEntity(Student.class);
MongoEntityInformation<Student, ObjectId> mongoEntityInformation = new MappingMongoEntityInformation<Student, ObjectId>(persistentEntity, school+"Students");
return new SimpleMongoRepository<Student, ObjectId>(mongoEntityInformation, mongoOperations);
}
}