MongoDB MapReduce: Not working as expected for more than 1000 records

前端 未结 1 1359
陌清茗
陌清茗 2021-01-21 00:26

I wrote a mapreduce function where the records are emitted in the following format

{userid:, {event:adduser, count:1}}
{userid:, {event:log         


        
相关标签:
1条回答
  • 2021-01-21 00:40

    The shape of the object you emit from your map function must be the same as the object returned from your reduce function, as the results of a reduce can get fed back into reduce when processing large numbers of docs (like in this case).

    So you need to change your emit to emit docs like this:

    {userid:<xyz>, {events:[{adduser: 1}], allEventCount:1}}
    {userid:<xyz>, {events:[{login: 1}], allEventCount:1}}
    

    and then update your reduce function accordingly.

    0 讨论(0)
提交回复
热议问题