【发布时间】:2015-11-27 10:48:14
【问题描述】:
我搜索了如何在 Java Spring Data MongoDB 中设置复合索引。 SO和其他网站说添加:
@CompoundIndex(name = "test_name", def = "{'subDeviceIndex : 1, 'sensorIndex : 1'}")
或者
@CompoundIndexes({
@CompoundIndex(name = "test_name", def = "{'subDeviceIndex : 1, 'sensorIndex : 1'}")
})
@Document 注释上方(我在上面和下面都尝试过)应该保存复合索引,但是它不会保存复合索引并清除我现有的索引。在下面找到该类的 sn-p。集合正确保存,我可以提取数据 sn-p 只显示变量声明和注释。类的其余部分是 getter/setter 和 @PersistenceConstructor。
@Document(collection=SensorValueDAOImpl.COLLECTION)
public class SensorValue {
@Id
private String id;
@DBRef
@Indexed
private RootDevice rootDevice;
//0 means root device
@Indexed
private int subDeviceIndex;
//sensor number, starting from 0
@Indexed
private int sensorIndex;
private int presentValue;
private int lowestDetectedValue;
private int highestDetectedValue;
private int recordedValue;
private Date dateTime;
包含以下问题以供参考,因为它们没有解决问题:
How to use spring data mongo @CompoundIndex with sub collections?
@CompoundIndex not working in Spring Data MongoDB
谢谢!
【问题讨论】: