Skip to content

Instantly share code, notes, and snippets.

@parrish
Created May 15, 2014 19:55
Show Gist options
  • Save parrish/97bfac07a57f38efe360 to your computer and use it in GitHub Desktop.
Save parrish/97bfac07a57f38efe360 to your computer and use it in GitHub Desktop.
MongoDB unique classifiers per day
var userMap = function() {
day = Date.UTC(this.created_at.getFullYear(), this.created_at.getMonth(), this.created_at.getDate());
emit({ day: day, user_id: this.user_id }, { count: 1 });
}
var userReduce = function(key, values) {
var count = 0;
values.forEach(function(v) {
count += v['count'];
});
return { count: count };
}
db.galaxy_zoo_classifications.mapReduce(userMap, userReduce, { out: 'user_classifications_per_day' })
var classifyMap = function() {
emit(this['_id']['day'] / 1000, { count: 1 });
}
db.user_classifications_per_day.mapReduce(classifyMap, userReduce, { out: 'classifying_users_per_day' })
db.classifying_users_per_day.findOne()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment