Created
May 15, 2014 19:55
-
-
Save parrish/97bfac07a57f38efe360 to your computer and use it in GitHub Desktop.
MongoDB unique classifiers per day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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