Created
March 21, 2011 01:44
-
-
Save csanz/878897 to your computer and use it in GitHub Desktop.
Looking for duplicates / Simple script example
This file contains 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.users.group({ key: { name:true }, | |
cond: { "created_at"}, | |
initial: { count: 0 }, | |
reduce: function(obj,out) { out.count ++ ; }}); | |
/* | |
Note1: make sure you put the initial declaration above reduce or else the count variable never gets set | |
Note2: group() can't handle more than 10000 unique keys, so for large dbs you are better off using straight up map reduce. | |
*/ | |
This file contains 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
m = function () { | |
emit(this.name, 1); | |
}; | |
r = function (k, vals) { | |
return Array.sum(vals); | |
}; | |
/* shell | |
> res = db.users.mapReduce(m,r); | |
{ | |
"result" : "tmp.mr.mapreduce_1300684269_8", | |
"timeMillis" : 22, | |
"counts" : { | |
"input" : 11, | |
"emit" : 11, | |
"output" : 5 | |
}, | |
"ok" : 1, | |
} | |
> db[res.result].count({ "value": { $gte: 2 }}); | |
3 | |
*/ | |
db[res.result].drop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks very much for your effort. This helped me a lot!