Skip to content

Instantly share code, notes, and snippets.

View markandrewj's full-sized avatar

Mark Jackson markandrewj

  • Canada
View GitHub Profile
// Universal mongodb reduce function for complex objects
//
// Example:
//
// emit({ total_views: 3, page_type: {home: 1, product: 2}, site_id: [1] })
// emit({total_views: 5, page_type: {home: 1, collection: 4}, site_id: [2]})
//
// -> reduce
//
// { total_views: 8, page_type: { home: 2, product: 2, collection: 4 }, site_id: [1,2] }