Created
December 20, 2012 17:23
-
-
Save anonymous/4346929 to your computer and use it in GitHub Desktop.
Redundant shard key indexes with mongo 2.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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