Skip to content

Instantly share code, notes, and snippets.

@peterzawistowicz
Created May 27, 2015 21:19
Show Gist options
  • Save peterzawistowicz/82b16920983cdd30f94b to your computer and use it in GitHub Desktop.
Save peterzawistowicz/82b16920983cdd30f94b to your computer and use it in GitHub Desktop.
var map = function() { emit(this.userId, 1); } // emit samples by userId with value of 1
var reduce = function(key, values)
{ return Array.sum(values); } // sum the total samples per user
db.activities.mapreduce(map, reduce,
{ query: { time: { $gt: NOW-1H } }, // time bound the query to the last hour
out: { replace: "lastHourUniques", 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