Skip to content

Instantly share code, notes, and snippets.

@ciudilo
Created February 6, 2018 19:08
Show Gist options
  • Save ciudilo/6b3875f3e8e85c551ebacd65c016844a to your computer and use it in GitHub Desktop.
Save ciudilo/6b3875f3e8e85c551ebacd65c016844a to your computer and use it in GitHub Desktop.
function checkDatabase(dbName) {
var database = db.getSisterDB(dbName);
database.getCollectionNames().forEach(function(colName){checkCollection(database, colName)});
};
function checkCollection(database, colName) {
database.getCollection(colName).getIndexes().forEach(function(indexDoc){
if(indexDoc.unique) {
if (Object.keys(indexDoc.key).length > 1) {
printjson("Cannot check compound indexe for uniqness. Sorry...");
return;
}
var fieldName = indexDoc.name.substr(0, indexDoc.name.indexOf('_'));
checkUniqueIndexIsUnique(database, colName, fieldName);
}
})
};
db.adminCommand({listDatabases: 1}).databases.forEach(function(dbDoc){checkDatabase(dbDoc.name)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment