3
我正在努力爲我們的MongoDB部署生成刪除/創建腳本。我們希望到達所有MongoDB數據庫/集合在我們的開發,測試和生產環境中在結構上相同的地方。爲此,我們決定在ensureIndex時間命名索引。問題是,我如何更新已經存在的索引的名稱?我知道不工作只是重新運行ensureIndex與像指定的「名」 ....我可以更改現有索引的名稱嗎?
// existing indexes, note its name is "groups_1"...
dmReplSet:PRIMARY> db.system.indexes.find();
{ "v" : 1, "key" : { "groups" : 1 }, "ns" : "test.config", "name" : "groups_1" }
...
// attempt to change its name by re-issue ensureIndex command...
dmReplSet:PRIMARY> db.config.ensureIndex({ "groups" : 1 }, { "name" : "config_groups_ix" });
// Nope, name is still "groups_1"...
dmReplSet:PRIMARY> db.system.indexes.find();
{ "v" : 1, "key" : { "groups" : 1 }, "ns" : "test.config", "name" : "groups_1" }
...
我怎麼可以更新已存在的蒙戈索引的名稱?這樣做有沒有風險?
我認爲你必須刪除現有的索引,然後用你想要的名字重新創建它。 – JohnnyHK
謝謝,但我希望有更好的方法。我的兩個生產指數都在一個相當大的集合上; 1600萬份文檔並不斷增長。 –
呃。剛剛與10gen球員簽入。 @JohnnyHK是正確的。您不能在mongo中重命名和編制索引。您只能刪除並重新創建它。嘆。 –