Skip to content

Instantly share code, notes, and snippets.

@peterzawistowicz
Created May 27, 2015 21:20
Show Gist options
  • Save peterzawistowicz/aa5482aa594c2e75acbb to your computer and use it in GitHub Desktop.
Save peterzawistowicz/aa5482aa594c2e75acbb to your computer and use it in GitHub Desktop.
var map = function() { emit(userId, this.itemId); } // emit samples as userId: itemId
var reduce = function(key, values)
{ return values; } // Return the array of itemIds the user has bought
db.activities.mapReduce(map, reduce,
{ query: { type: “ORDER”, time: { $gt: NOW-24H }}, // include only activities of type order int he last day
out: { replace: "lastDayOrders", sharded: true }) // persist the output to a collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment