I am undertaking an effort to produce drop/create scripts for our MongoDB deployment. We would like to get to a place where all MongoDB database/collections are structurally identical across our dev, test, and production environments. To this end, we have decided to name the indexes at ensureIndex time. The problem is, how do I update the name of indexes that already exist? What I know doesn't work is just re-running the ensureIndex with a "name" specified like....
// 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" }
...
How can I update the name of a mongo index that already exists? Is there any risk in doing this?