Created
December 17, 2010 05:52
-
-
Save ngmaloney/744545 to your computer and use it in GitHub Desktop.
Mongodb Max Length MapReduce
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
reduce = function(key,vals) { | |
return vals.sort(function(a,b){return b - a})[0]; | |
} | |
map = function() { | |
var map_send = function(k,v) { | |
emit(k,v.toString().length); | |
} | |
var recursive_mapper = function(obj,level) { | |
level = level || 0; | |
for(key in obj) { | |
if(level > 3) { | |
return false; | |
} | |
var type = typeof(obj[key]); | |
switch(type) { | |
case 'string': | |
case 'number': | |
map_send(key,obj[key]); | |
break; | |
case 'object': | |
level++; | |
recursive_mapper(obj[key],level); | |
break; | |
} | |
} | |
} | |
recursive_mapper(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment