3 ms·
Understanding Map Reduce
- mise 16y agoThank you times a thousand. From the PHP world, I can relate to mapping like this: $map = array() $map["$gameid_$year_$month_$day"][]['count'] = 3; ... $map["$gameid_$year_$month_$day"][]['count'] = 1; Then $arr gets reduced with another few steps of script.
- bricestacey 16y agoI've been learning mongodb for the past week, so I may be wrong. But unless his application logic added a condition on the hits collection, his last line when called repeatedly will duplicate existing counts. He'd need something like this where value is the last time he ran map_reduce. db['hits'].map_reduce(map, reduce, {query: {date:{$gt:value}}}) Alternatively, he could map_reduce the entire collection and instead of using upserts and inc, merge the result into the daily_hits collection. db['hits'].map_reduce(map, reduce, {out: {merge: 'daily_hits}}) See mongo mapreduce docs: http://www.mongodb.org/display/DOCS/MapReduce http://www.mongodb.org/display/DOCS/MapReduce
- latch 16y agoNo, you are right. I updated the article to include the missing step. It was original left out because I didn't think it really had to do anything with map and reduce...but then that's pretty silly, especially ince most of the article doesn't.