Skip to content

Instantly share code, notes, and snippets.

@jeffdeville
Created October 21, 2010 20:03
Show Gist options
  • Save jeffdeville/639210 to your computer and use it in GitHub Desktop.
Save jeffdeville/639210 to your computer and use it in GitHub Desktop.
Map User/Interests to Interest/Users
def self.update_map
map = 'function() {' +
'for (var i in this.interests) {' +
'if (this.interests[i]._id != null) {' +
'emit(this.interests[i]._id, {"users": this.facebook_id, "count": 1});' +
'}' +
'}' +
'}';
reduce = 'function(key, emits) {' +
'var all_users = Array(); var count = 0;' +
'for(var i in emits) {' +
'all_users = all_users.concat(emits[i].users);' +
'count += emits[i].count;' +
'}' +
'return {"users": all_users, "count": count};}';
User.collection.map_reduce(map, reduce,{:query => {:is_user => true}, :out => "interest_maps"})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment