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