2017-04-11 47 views
-1

我有一個索引,我需要修改。無法重新創建具有相同名稱的mongo索引

{ 
    "v" : 1, 
    "key" : { 
     "expectedDateTime" : 1 
    }, 
    "name" : "expectedDateTime_1", 
    "ns" : "expectation.expectation_data", 
    "expireAfterSeconds" : 43200 
} 

的expireAfterSeconds是不正確的,需要更改至432000.

當我放棄了指數似乎罰款

db.expectation_data.dropIndex({"expectedDateTime":1}) 
{ "nIndexesWas" : 4, "ok" : 1 } 

的getIndexes()顯示,該指數不存在。

然後當我嘗試重新創建索引我得到這個錯誤

db.expectation_data.createIndex({"expectedDateTime":1}, 
{expireAfterSeconds:432000,name:"expectedDateTime"}); 
{ 
    "ok" : 0, 
    "errmsg" : "Index with name: expectedDateTime already exists with different options", 
    "code" : 85 
} 

現在運行getIndexes(),我看到指數似乎已經與老TTL重建。我試過多次重複這個過程,但一次又一次地遇到同樣的問題。

我找不到任何說明我無法重新創建同名索引的文檔。如果我使用一個不同的名稱,它工作正常

db.expectation_data.createIndex({"expectedDateTime":1}, {expireAfterSeconds:432000}); 
. 
. 
>db.expectation_data.getIndexes() 
. 
. 
{ 
    "v" : 1, 
    "key" : { 
     "expectedDateTime" : 1 
    }, 
    "name" : "expectedDateTime_1", 
    "ns" : "expectation.expectation_data", 
    "expireAfterSeconds" : 432000 
} 

是否有相同名稱重新創建索引任何限制?

+1

這看起來像索引是自動重新創建(可能是一個正在運行的後臺進程或客戶端連接到MongoDB,它以編程方式調用ensureIndex?) – Matt

+0

@Matt - 如您所料。我剛剛發現並在幾分鐘前發佈了答案。 –

+0

如果你想,將其作爲答案發布,我會接受它:) –

回答

0

這看起來像索引刪除後自動重新創建。確保沒有使用ensureIndex@Index的應用程序 - 註釋正在連接到數據庫。

-1

事實證明。這是由於在舊超時的實體中使用了@Index註釋。當我進行索引更改時,應用程序仍在運行。

當我停止了應用程序,我能創建索引,因爲我原本預計

相關問題