在Spring Boot
项目中使用 MongoDB
,Order
类中的orderId
添加@Indexed
后在MongoDB
中未创建索引,原因是配置中的auto-index-creation
未设置为true
。
@Document(collection = "order")
public class Order {
@Id
private String id;
@Indexed(unique = true)
private String orderId;
private Integer count;
private BigDecimal amount;
private String parent;
}
spring:
data:
mongodb:
auto-index-creation: true # 默认为false,即不会自动创建索引,