Skip to content

Instantly share code, notes, and snippets.

@anvie
Created November 16, 2011 16:13
Show Gist options
  • Save anvie/1370500 to your computer and use it in GitHub Desktop.
Save anvie/1370500 to your computer and use it in GitHub Desktop.
mr non sharded collection
function () {
var t, user_id;
t = this;
user_id = t._id.toString();
this._followed_user_ids.forEach(function (fuid) {
var u;
u = db.user.findOne({
_id: ObjectId(fuid)
});
if (u) {
return u._followed_user_ids.forEach(function (fuid2) {
var pd, u2, user_pds, _i, _len, _ref;
if (t._followed_user_ids.indexOf(fuid2) === -1 && fuid2 !== user_id) {
u2 = db.user.findOne({
_id: ObjectId(fuid2)
}, {
'name': 1
});
if (u2) {
user_pds = [];
_ref = t.personal_descs;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
pd = _ref[_i];
pd = pd.replace(/^\s|\s$/g, "");
pd = pd.toLowerCase();
user_pds.push(pd);
}
return emit(fuid2 + ":" + user_id, {
user_id: ObjectId(user_id),
user_pds: user_pds,
name: u2.name,
mutual_count: 1,
mutual: [u.name],
score: 1
});
}
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment