MongoDB映射reduce函数语法

MongoDB映射reduce函数语法,mongodb,mapreduce,Mongodb,Mapreduce,我正在尝试将这个sql查询转换为MapReduce select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date '1993-07-01' and o_orderdate < date '1993-07-01' + interval '3' month and exists ( select

我正在尝试将这个sql查询转换为MapReduce

select
    o_orderpriority, 
    count(*) as order_count
from 
    orders
where 
    o_orderdate >= date '1993-07-01'
    and o_orderdate < date '1993-07-01' + interval '3' month
    and exists (
        select 
        *
        from 
        lineitem
        where 
        l_orderkey = o_orderkey
        and l_commitdate < l_receiptdate
    )
group by 
    o_orderpriority
order by 
    o_orderpriority;

问题是您的emit和reduce函数没有返回相同的内容

映射函数将发出以下值:

{count: 1}
这意味着reduce必须返回相同的格式

您正在reduce中返回一个简单的值:

return count;
您可以将emit更改为仅emit 1而不是JSON文档,然后不必更改reduce,否则更改reduce以返回JSON文档{count:X},其中X是计算的计数


仅供参考,这导致错误“值太大而无法减少”的原因是,一旦您像这样混合类型,“+”运算符开始连接您的值,而不是添加它们,最终它会变得太大。要查看如何调试此问题,我建议您在第9行的页面

中缺少“.”如果(this.o_lineitem[I].l_commitdateemit(此.o_行项目[i].o_顺序优先级,计数顺序:1)但应该是
emit(this.o_lineitem[i].o_orderpriority,count_order)@ulima69:oops,应该已经读取了reduce()。。所以我认为您实际上想要:
emit(this.o_lineitem[i].o_orderpriority,{count_order:1})
。请注意,reduce使用的是
order\u count
,似乎没有将任何结果写入
ret
值。只需使用emit(this.o\u lineitem[i].o\u orderpriority,1)-您不需要发出文档。
{count: 1}
return count;