2
那么我尝试翻译这个SQL查询来映射减少MongoDB的地图减少函数的语法
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;
香港专业教育学院尝试了以下地图缩小功能
db.runCommand({
mapreduce: "orders",
query: {
o_orderdate: {'$gte': new Date("July 01, 1993")},
o_orderdate: {'$lt': new Date("Oct 01, 1993")}
},
map: function Map() {
for(var i in this.o_lineitem) {
if(this.o_lineitem[i].l_commitdate < this.o_lineitem[i].l_receiptdate) {
var o_orderpriority = this.o_lineitem[i].o_orderpriority;
emit(o_orderpriority, {count: 1});
}
}
},
reduce: function(key, values) {
var count= 0;
for (var i = 0; i < values.length; i++) {
count+= values[i];
}
return count;
},
out: 'query004'
});
艾当运行我得到遵循警报
星期六年08月11二十时44分32秒的SyntaxError:错过)后条件(壳):9
对我来说,没有)失踪,是吗?
我没有通过@Stenie指出改正,但现在我有如下问题
{
"assertion" : "value too large to reduce",
"assertionCode" : 13070,
"errmsg" : "db assertion failure",
"ok" : 0
}
您遗漏了“”第9行:if(this.o_lineitem [i] .l_commitdate
2012-08-12 05:58:20
@AsyaKamsky前的最后]我把点,但问题仍然存在: 太阳08月12日9时03分31秒语法错误:10 – ulima69 2012-08-12 12:05:58
@ ulima69:后参数列表(壳)失踪)10号线已经发出'(本.o_lineitem [I] .o_orderpriority,count_order:1);'但应该是'发射(this.o_lineitem [I] .o_orderpriority,count_order);'。 – Stennie 2012-08-12 13:13:45