Skip to content

Instantly share code, notes, and snippets.

@bayleedev
Forked from na1s/index_generator.js
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayleedev/8ce12fda247523e40d5a to your computer and use it in GitHub Desktop.
Save bayleedev/8ce12fda247523e40d5a to your computer and use it in GitHub Desktop.
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+",{ \"background\":true, \"name\":\"" + i["name"]+"\"});");
}
});}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment