Google Groups

Re: Incorrect results in map_reduce.


Venkat May 5, 2012 5:34 AM
Posted in group: mongodb-user
Hi,

When I debugged this, if there is only one document for the specified
key, the reduce function is not getting called for those. But the
finalize function is getting called for all of them. Is that the
behavior?

mongos> db.domain_aggregate.find()
{ "_id" : "00269.net", "value" : 1 }
{ "_id" : "0ab.fr", "value" : 2 }
{ "_id" : "0am.co", "value" : 1 }
{ "_id" : "0z.fr", "value" : 2 }

In the above example, the domain = 0am.co has only one entry. whereas
domain = 0z.fr has two entries..


On May 5, 2:46 pm, Venkat <s.ramanan.venk...@gmail.com> wrote:
> btw my collections are sharded. Is that the problem?
>
> On May 5, 2:44 pm, Venkat <s.ramanan.venk...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I suspect that the map reduce that I do produces incorrect result. I
> > stripped down my map reduce functions to the following.
>
> >         m = Code("function() { emit(this.domain, 1) }")
> >         r = Code("function(key, values) { "
> >                  "    return 2;"
> >                  "}")
>
> >         self.domain_surl.map_reduce(m, r, out = SON([('replace',
> > 'domain_aggregate'), ('db', 'twitter_repute')]), query = {'time':
> > {'$lte': start_ts, '$gte': end_ts}})
>
> > With the above map reduce I expect all the the 'value' field for the
> > aggregate collection as '2'. But for some documents it is same as what
> > I emitted in the map function. For the above map reduce I am getting
> > the following result.
>
> > mongos> db.domain_aggregate.find()
> > { "_id" : "00269.net", "value" : 1 }
> > { "_id" : "0ab.fr", "value" : 2 }
> > { "_id" : "0am.co", "value" : 1 }
> > { "_id" : "0z.fr", "value" : 2 }
> > { "_id" : "1-800flowers.com", "value" : 1 }
> > { "_id" : "1001mutiarakata.com", "value" : 1 }
> > { "_id" : "1001tracklists.com", "value" : 1 }
> > { "_id" : "100joursenor.be", "value" : 1 }
> > { "_id" : "100tb.com", "value" : 1 }
> > { "_id" : "1101.jp", "value" : 1 }
> > { "_id" : "11alive.com", "value" : 1 }
> > { "_id" : "11st.co.kr", "value" : 1 }
> > { "_id" : "12select.nl", "value" : 1 }
> > { "_id" : "1day1shot.jp", "value" : 1 }
> > { "_id" : "1foco.com", "value" : 1 }
> > { "_id" : "1radio.org", "value" : 1 }
> > { "_id" : "2-d.jp", "value" : 2 }
> > { "_id" : "20dollars2surf.com", "value" : 2 }
> > { "_id" : "20min.fr", "value" : 2 }
> > { "_id" : "20minutes.fr", "value" : 1 }
>
> > Why am I gettting the value 1 at all. I am supposed to get whatever I
> > returned from the reduce function rit? Or am I missing something?