标题翻译
CompoundIndexes annotation not working in MongoDB and Spring
问题
我正在尝试在Spring中为文档创建复合索引。我可以在Mongoshell上手动创建,但在Spring中却不起作用。以下是我的代码。
@Document(collection = "Cars")
@CompoundIndexes({
@CompoundIndex(def = "{'brand':1,'model':1,'colour':1,'fuelTypes':1}", name = "cars_compound_indexes", unique = true)
})
public class Car {
private String brand;
private String model;
private List<FuelType> fuelTypes;
private String colour;
}
还有,当输入重复数据时,如何更新文档?
英文翻译
I'm trying to create compoundIndex on document in Spring. I could create manually on Mongoshell. But in Spring it's not working. Here is my code.
Document(collection = "Cars")
@CompoundIndexes({
@CompoundIndex(def = "{'brand':1,'model':1,'colour':1,'fuelTypes':1}", name = "cars_compound_indexes",unique = true)
})
public class Car {
private String brand;
private String model;
private List<FuelType> fuelTypes;
private String colour;
}
And also how can I update document when duplicate is entered.
专注分享java语言的经验与见解,让所有开发者获益!
评论