【问题标题】:How can I define index on inherited fields in MongoDB with Spring Data?如何使用 Spring Data 在 MongoDB 中的继承字段上定义索引?
【发布时间】:2018-12-17 07:06:46
【问题描述】:

我有一个持久类,它扩展了定义了它的一些字段的父级。使用 Spring Data Mongo,我可以在持久性字段上使用 @Indexed 注释在相应的集合上创建索引。但是,在继承字段的情况下,我只能通过父类访问它们。我可能可以将注释放在那里,但我不想为扩展父类的每个 Collection 创建索引。我可以使用@CompoundIndex(单值)来解决这个问题吗?

【问题讨论】:

    标签: java spring spring-boot spring-data spring-data-mongodb


    【解决方案1】:

    在做了一些本地测试后,我发现,是的,我可以使用@CompoundIndex 来解决这个问题。

    【讨论】:

      猜你喜欢
      • 2019-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 2012-02-06
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多