7
我正在使用Spring Data MongoDB開發應用程序。我想在我的一個模型上創建一個複合索引。我在頂部添加了@CompoundIndex註釋,如下所示:@CompoundIndex在Spring Data MongoDB中不起作用
@Document
@CompoundIndexes({
@CompoundIndex(name = "name_", def = "{ 'tenantId': 1, 'name': 1 }", unique = true)
})
public class MyModel {
}
但是,索引未創建。我也試圖直接將@CompoundIndex
放在課堂上方。該集合仍然缺少索引。當像這樣創建的相同指標的定義是工作的罰款:
mongoTemplate.indexOps(MyModel.class).ensureIndex(new Index().named("name_").on("tenantId", Direction.ASC).on("name", Direction.ASC).unique());
我寧願使用索引的基於註解的定義。任何想法爲什麼這不起作用?
您是否嘗試過http://pastebin.com/PynPCgRY? – chridam
我現在做了,它不會改變行爲... – fynn
嗨!我可以請你發佈整個申請嗎?至少能夠提供Spring上下文會很好。 – danidemi