Created
January 30, 2014 19:33
-
-
Save normgraham/8716967 to your computer and use it in GitHub Desktop.
Prints a list of duplicate keys (here as the Value field in the StringLookup collection of all dbs) that are strings shorter than the maximum key length of 1024 taking overhead into account, which makes the maximum string key length to be 1011.
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
| var printDupValidKeys = function() { | |
| db.adminCommand({"listDatabases":1}).databases.forEach( | |
| function(sdb) { | |
| print(sdb.name); | |
| try { | |
| dupes=db.getSiblingDB(sdb.name).StringLookup.aggregate( | |
| [ { $group: { | |
| "_id" : "$Value", | |
| "c": { "$sum" : 1 } } }, | |
| { $match : { | |
| "c" : {"$gt" : 1 } } } ] ); | |
| dupes.result.forEach( | |
| function(dupe) { | |
| if (dupe._id.length < 1012) | |
| printjson(dupe); | |
| }); | |
| } | |
| catch (e) { } | |
| } | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment