Skip to content

Instantly share code, notes, and snippets.

@pitchart
Created January 16, 2020 08:33
Show Gist options
  • Save pitchart/7be3c9acfdba26f56173ce673194a4b3 to your computer and use it in GitHub Desktop.
Save pitchart/7be3c9acfdba26f56173ce673194a4b3 to your computer and use it in GitHub Desktop.
Mongodb extract index creation script
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