-
-
Save aktasch/481e73eee901a4fae6c8da5ce1b4aeab to your computer and use it in GitHub Desktop.
This file contains 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
db.adminCommand({'listDatabases':1, nameOnly:true}).databases.forEach(function(mydb) { | |
var dbName = mydb.name; | |
if (! ["admin", "config", "local"].includes(dbName)) { | |
var currentDB = db.getSiblingDB(dbName); | |
var collectionNames = currentDB.getCollectionNames(); | |
collectionNames.forEach(function (collName) { | |
if (/^system\./.test(collName)){ | |
return; | |
} | |
var indexes = currentDB[collName].getIndexes(); | |
//print(` ${collName} ${indexes}`); | |
indexes.forEach(function(index){ | |
delete index.v; | |
delete index.ns; | |
var key = index.key; | |
delete index.key | |
print(`db.getSiblingDB('${dbName}').${collName}.createIndex(${JSON.stringify(key)}, ${JSON.stringify(index)})`) | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment