mongodb map-reduce output doubles <p>my source database have documents like..</p> <pre><code>{date:14, month:1, year:2011, name:"abc", item:"A"} {date:14, month:1, year:2011, name:"abc", item:"B"} {date:14, month:1, year:2011, name:"def", item:"A"} {date:14, month:1, year:2011, name:"def", item:"B"} {date:15, month:1, year:2011, name:"abc", item:"A"} {date:16, month:1, year:2011, name:"abc", item:"A"} {date:15, month:1, year:2011, name:"def", item:"A"} {date:16, month:1, year:2011, name:"def", item:"A"} </code></pre> <p>and my map reduce is like...</p> <pre><code>var m = function(){ emit({name:this.name, date:this.date, month:this.month, year:this.year}, {count:1}) } var r = function(key, values) { var total_count = 0; values.forEach(function(doc) { total_count += doc.count; }); return {count:total_count}; }; var res = db.source.mapReduce(m, r, { out : { "merge" : "bb_import_trend" } } ); </code></pre> <p>so "myoutput" collection will have counts like this....</p> <pre><code>{ "_id" : { date : 14, month : 1, year : 2011, name : "abc" }, "_value" : { "count" : 2 } }, { "_id" : { date : 14, month : 1, year : 2011, name : "def" }, "_value" : { "count" : 2 } }, { "_id" : { date : 15, month : 1, year : 2011, name : "abc" }, "_value" : { "count" : 1 } }, { "_id" : { date : 15, month : 1, year : 2011, name : "def" }, "_value" : { "count" : 1 } }, { "_id" : { date : 16, month : 1, year : 2011, name : "abc" }, "_value" : { "count" : 1 } }, { "_id" : { date : 16, month : 1, year : 2011, name : "def" }, "_value" : { "count" : 1 } } </code></pre> <p>so total 6 documents</p> <p>so when aother three documents of date 17 like...</p> <pre><code>{date:17, month:1, year:2011, name:"abc", item:"A"} {date:17, month:1, year:2011, name:"abc", item:"B"} {date:17, month:1, year:2011, name:"def", item:"A"} </code></pre> <p>has been added to my source collection...and again i am running map-reduce it should be jus addition of two documents like...</p> <p>previous 6 plus</p> <pre><code>... { "_id" : { date : 17, month : 1, year : 2011, name : "abc" }, "_value" : { "count" : 2 } }, { "_id" : { date : 17, month : 1, year : 2011, name : "def" }, "_value" : { "count" : 1 } } </code></pre> <p>but instead of this it duplicates all the previous 6 documents and adds another 2 new ones..so total of 14 documents in my output collection(though i 've used merge in output).</p> <p>Note > : when i am using another database having same source collection and doing the same procedure it gives me desired output(of only 8 collection).but my database using by my gui is still duplicating the old ones.</p>