

Understanding Map Reduce - latch
http://openmymind.net/2011/1/20/Understanding-Map-Reduce

======
mise
Thank 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
I'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>

~~~
latch
No, 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.

