Morphia:使用弃用配置选项的集合索引(复合键索引)

Morphia: Index on collection using deprecated configuration options (Composite key Index)

最近我们从 Morphia 0.99 升级到 1。2.x 和 MongoDB 到 3.2。

之后,我们在使用具有复合键索引的集合对象时看到了很多警告消息。

警告示例如下:

WARNING: This index on 'RowData' is using deprecated configuration options. Please update to use the fields value on @Index: @org.mongodb.morphia.annotations.Index(unique=false, dropDups=false, name=, background=false, expireAfterSeconds=-1, value=resultSetId, rowSequence, disableValidation=false, sparse=false, fields=[], options=@org.mongodb.morphia.annotations.IndexOptions(unique=false, dropDups=false, name=, background=false, expireAfterSeconds=-1, disableValidation=false, language=, languageOverride=, sparse=false))

Object上的索引标签如下:

@Entity(noClassnameStored = true)
@Indexes({@Index("resultSetId, rowSequence")})
public class RowData implements Transportable { ... }

有什么方法可以抑制警告信息吗?

无需取消警告,它会告诉您您正在使用的配置很快将不受支持。

改用这个

@Indexes({ 
    @Index(fields = {@Field(value = "resultSetId"), @Field("rowSequence")})
})

索引选项注意事项:
如果从旧的 Index 语法迁移到最新的,要么完全保留 IndexOptions 部分(如上所示),要么确保在更改之前在集合上设置相同的选项。否则,您将获得与 IndexOptions 相关的异常。