3 ms·
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 c
by bricestacey 16y ago
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 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.