Created
September 1, 2022 22:15
-
-
Save mhelmstetter/70ef46c6bcad132e66d015c7ca22a5d1 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