I can't seem to get my MapReduce reduce function to work properly. Here is my map function:
function Map() {
day = Date.UTC(this.TimeStamp.getFullYear(), this.TimeStamp.getMonth(),this.TimeStamp.getDate());
emit(
{
search_dt: new Date(day),
user_id: this.UserId
},
{
timestamp: this.TimeStamp
}
);
}
And here is my reduce function:
function Reduce(key, values) {
var result = [timestamp:0];
values.forEach(function(value){
if (!value.timestamp)
continue;
if (result.timestamp < value.timestamp)
result.timestamp = value.timestamp;
});
return result;
}
I want to retrieve the latest date of the grouped object. What am I doing wrong?
Have you considered using either of the following approaches?
Find the MAX timeStampField in the collection:
OR:
Find the MAX timeStampField, per user_id in the collection (if DB not sharded):