Created
January 16, 2020 08:33
-
-
Save pitchart/7be3c9acfdba26f56173ce673194a4b3 to your computer and use it in GitHub Desktop.
Mongodb extract index creation script
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
db.getCollectionInfos({ type: "collection" }).forEach(function(coll) { | |
db[coll.name].getIndexes().forEach(function(index) { | |
if ("_id_" !== index.name) { | |
print("db." + coll.name + ".createIndex(" + tojson(index.key) + ", "+tojson({name:index.name})+");"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment