Skip to content

Instantly share code, notes, and snippets.

@hoffrocket
Forked from anonymous/redundant_shard_keys.js
Created February 18, 2013 18:39
Show Gist options
  • Save hoffrocket/4979583 to your computer and use it in GitHub Desktop.
Save hoffrocket/4979583 to your computer and use it in GitHub Desktop.
db.getCollectionNames().forEach(function(n){
var shardConfig = db.getSisterDB('config').collections.findOne({_id:"foursquare." + n},{key:1});
if (shardConfig){
var shardKeyNameParts = [];
for (var keyPart in shardConfig.key) {
shardKeyNameParts.push(keyPart + "_" + shardConfig.key[keyPart]);
}
var shardKeyName = shardKeyNameParts.join('_');
var shardKeySizeMb = Math.round(db[n].stats().indexSizes[shardKeyName]/1024/1024);
db[n].getIndexes().forEach(function(i){
if (i.name.indexOf(shardKeyName) == 0 && i.name != shardKeyName) {
print("Possible duplicates for " + n + ": " + tojson(i.key) + " with shardKey " + tojson(shardConfig.key) + " will save " + shardKeySizeMb + " mb");
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment