我看到蒙戈使用進行逐步減少地圖任務的錯綜複雜的行爲反饋到降低降低函數的結果。輸入集合是大組包含的文件:爲什麼使用MongoDB中的MapReduce
{_id:,網址: '從我的時髦的網站一些URL'}
這是我簡單的地圖功能:
map: function() {
emit(this.url, {count: 1, id: this._id});
}
而減少(有很多調試打印的原木如下圖所示):
reduce: function (key, values) {
var count = 0;
var lastId = null;
var first = null;
if (typeof values[0].id == "undefined") {
print("bad id");
printjson(key);
printjson(values[0]);
return null;
} else {
print ("good id");
printjson(key);
printjson(values[0]);
}
first = ObjectId(values[0].id).getTimestamp();
values.forEach(function(v) {
count += v.count;
last = ObjectId(v.id).getTimestamp();
lastId = v.id;
});
return {
count: count,
first: first,
last: lastId,
lastCounted: lastId
};
}
以下是我叫的MapReduce:
mrparams.out = {reduce: this.output};
mrparams.limit = 100;
mrparams.query = {'_id': {'$gt': mongoId(lastId.toHexString())}};
mrparams.finalize = null;
mrdb.mapReduce(this.map, this.reduce, mrparams, function(d) {
console.log("Finished mr", d);
callback();
});
這讓每一個時間間隔,作業是在與後lastId它的時間之前運行記錄開始記錄數量限制運行在cron型的方式來完成。
非常基本的增量映射減少的東西...
但是,當我運行它,我看到了減少methond的返回值被傳遞迴降低的方法。這裏是日誌的快照:
XXXgood ID 「http://www.nytimes.com/2013/04/23/technology/germany-fines-google-over-data-collection.html」 { 「計數」:1, 「ID」:物件( 「5175a065b25f029a1d0927e6」)}
好ID 「http://www.nytimes.com/2013/04/23/world/middleeast/israel-hagel-iran.html」 {「計「:1, 」ID「:的ObjectId(」 5175a065d7f115dd41097df6 「)}
良好ID 」 http://www.nytimes.com/interactive/2013/04/22/sports/boston-moment.html 「 { 」計數「:1, 」ID「:的ObjectId(」 5175a0657c9c963654094d25" )}
YYYThu 06月20 11時42分11秒[conn19938]查詢vox.system.indexes查詢:{NS: 「vox.tmp.mr.pi_analytics_spark_trending_inventories_6667_inc」} nreturned:1個reslen:131 0毫秒 星期四06月20 11時42分11秒[ conn19938]查詢 vox.tmp.mr.pi_analytics_spark_trending_inventories_6667 nreturned:9 reslen:1716 0毫秒
ZZZbad ID 「http://www.nytimes.com/2013/04/22/business/comedy-central-to-host-comedy-festival-on-twitter.html」 { 「計數」:2, 「第一」:ISODate(「2013-04-22T20 :41:11Z 「), 」最後「:的ObjectId(」 5175a067b25f029a1d092802 「), 」lastCounted「:的ObjectId(」 5175a067b25f029a1d092802" ) }
壞ID 「http://www.nytimes.com/2013/04/22/business/media/in-boston-cnn-stumbles-in-rush-to-break-news.html」 { 「計數」:7, 「第一」:ISODate( 「2013-04-22T20:41:09Z」), 「最後」:的ObjectId( 「5175a067d7f115dd41097e3c」), 「lastCounted」:物件(「5175a067d7f115dd41097e3c」) }
XXX - 一堆(含計數和id的值) YYY從我的地圖功能發出的記錄 - 某種蒙戈的甚至是我不熟悉與 ZZZ - 事件發生後,減少調用前減少工作的輸出...
TLDR,當我運行map reduce時,減少會很好,直到mongo進程運行,然後我開始看到傳遞給我的reduce函數的先前reduce函數的返回值。
任何想法爲什麼/如何這是可能的?
運行蒙戈提前
我認爲這裏描述的很好:http://docs.mongodb.org/manual/reference/command/mapReduce/#requirements-for-the-reduce-function –