`CompoundIndexes`注解在MongoDB和Spring中不起作用。

huangapple 未分类评论50阅读模式
标题翻译

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 = &quot;Cars&quot;)
@CompoundIndexes({
        @CompoundIndex(def = &quot;{&#39;brand&#39;:1,&#39;model&#39;:1,&#39;colour&#39;:1,&#39;fuelTypes&#39;:1}&quot;, name = &quot;cars_compound_indexes&quot;,unique = true)
})

public class Car {
    private String brand;
    private String model;
    private List&lt;FuelType&gt; fuelTypes;
    private String colour;
}

And also how can I update document when duplicate is entered.

huangapple
  • 本文由 发表于 2020年5月31日 02:21:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/62106890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定