Skip to content

Instantly share code, notes, and snippets.

@chrisvaughn
chrisvaughn / mongo_dups.js
Created August 19, 2011 20:49
count dups in mongo with mapReduce
//count dups in mongo with mapReduce
m = function() { emit(this.user_id, 1); };
r = function (k, vals) { return Array.sum(vals); };
res = db.tasks.mapReduce(m, r, { out : {replace : "results", db : "mr"}});
// more difficult
function map() {
var sorted = this._keywords.sort();
key = sorted.join(" ");
var ret = {title : this.title, id : this._id, total: 1};