问题:mongodb索引不是通过Spring数据创建的
我有一个spring引导应用程序和MongoDB作为数据库.
我有一个实体类:
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document(COLLECTION_NAME)
public class PersonEntity {
public static final String COLLECTION_NAME = "person_info";
private static final String PERSON_NAME = "person_name";
@Id
private PersonId id;
@Field(name = PERSON_NAME)
private String personName;
@Indexed(name = "ttl_index", expireAfterSeconds=20)
private LocalDateTime date;
}我使用这个存储库将一个新文档持久化到MongoDB:
public interface SellerRequestInfoRepository extends ReactiveMongoRepository<PersonEntityEntity, PersonId> {}使用
personRepository.save(entity);但是,在输入Person文档之后,不会在MongoDB上创建TTL索引:
拜托,忠告,我做错了什么
发布于 2022-05-16 13:27:33
我引用文档
Spring数据MongoDB可以自动为带有@Document注释的实体类型创建索引。索引创建必须从3.0版本开始显式启用,以防止集合生命周期和性能影响的不理想效果。
启用自动索引创建了吗?因为如果没有,这很可能就是没有创建索引的原因。
使用Spring,您可以在application.yml中使用以下配置启用自动索引创建
spring:
data:
mongodb:
auto-index-creation: true或者如果你更喜欢房产:
spring.data.mongodb.auto-index-creation=truehttps://stackoverflow.com/questions/72259387
复制相似问题