Skip to content

Instantly share code, notes, and snippets.

@Maxhodges
Created May 7, 2018 05:43
Show Gist options
  • Save Maxhodges/9375cc3cb77e856a695cc51c6fbde5b1 to your computer and use it in GitHub Desktop.
Save Maxhodges/9375cc3cb77e856a695cc51c6fbde5b1 to your computer and use it in GitHub Desktop.
find 'safe' collection indexes
use whiterabbit
db.indexes.find();
db.shippingOrders.getIndexes();
db.getCollectionNames().forEach(function(collection) {
if (db[collection]) {
indexes = db[collection].getIndexes();
var filterIndexes = Object.keys(indexes).filter(function(i) {
return Object.hasOwnProperty.call(indexes[i], "safe")
})
if (filterIndexes.length > 0) {
indexNames = filterIndexes.map(function(i) {return indexes[i].name});
print("Indexes for " + collection + ' ' + JSON.stringify(indexNames));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment