Created
February 4, 2013 05:56
-
-
Save na1s/4705234 to your computer and use it in GitHub Desktop.
Mongodb index command generator from database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var r = new RegExp("system"); | |
db.getCollectionNames().forEach( | |
function(c){ | |
if(!r.test(c)){ | |
var indexes = db[c].getIndexes(); | |
indexes.forEach(function(i){ | |
var val = i["key"].toSource(); | |
var trimmedValue = val.substr(1,val.length-2); | |
if (trimmedValue !="{_id:1}") | |
{ | |
print("db."+c+".ensureIndex("+trimmedValue+",{ \"name\":\"" + i["name"]+"\"});"); | |
} | |
});} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment