Skip to content

Instantly share code, notes, and snippets.

@josephmosby
Created March 20, 2015 19:43
Show Gist options
  • Save josephmosby/50bb528c2833757e18c3 to your computer and use it in GitHub Desktop.
Save josephmosby/50bb528c2833757e18c3 to your computer and use it in GitHub Desktop.
Index everything in a MongoDB collection
db.system.js.save(
{
_id: "indexAll",
value: function() {
colls = db.getCollectionNames();
for (var i = 0; i < colls.length; i++) {
if (colls[i] != "system.indexes") {
db[colls[i]].createIndex( {"$**":"text"}, {name: "TextIndex"});
}
}
}
}
)
// invoke with:
// db.loadServerScripts();
// indexAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment