我收集了2,000,000份文件。当我运行mapreduce查询时,它会提供一个集合作为180,000个文档的结果。我的map reduce函数的代码如下:
db.products.mapReduce(
function(){
var key=this.category_id;
var value={value:[{
id:this._id,
status:this.status,
additional_images:this.additional_images,
image:this.image,
product_url:this.product_url,
colors:this.colors,
api:this.api,
sku:this.sku,
price:this.price,
api_updated_on:this.api_updated_on,
description:this.description,
brand:this.brand,
category_name:this.category_name,
category_id:this.category_id,
name:this.name,
product_id:this.product_id,
count:1
}]
};
emit(key,value);
},
function(key,values){
var objcollection={value:[]};
var count=1;
values.forEach( function(item) {
item=item.value[0];
//var test_obj={sku:"",name:"",catid:"",productid:"",count:""};
var item_obj={
id:"",
status:"",
additional_images:"",
image:"",
product_url:"",
colors:"",
api:"",
sku:"",
product_hash:"",
price:"",
api_updated_on:"",
description:"",
brand:"",
category_name:"",
category_id:"",
category_id:"",
name:"",
product_id:"",
count:""
};
item_obj.id=item.id;
item_obj.status=item.status;
item_obj.additional_images=item.additional_images;
item_obj.image=item.image;
item_obj.product_url=item.product_url;
item_obj.colors=item.colors;
item_obj.api=item.api;
item_obj.sku=item.sku;
item_obj.price=item.price;
item_obj.api_updated_on=item.api_updated_on;
item_obj.description=item.description;
item_obj.brand=item.brand;
item_obj.category_name=item.category_name;
item_obj.category_id=item.category_id;
item_obj.name=item.name;
item_obj.product_id=item.product_id;
item_obj.count=count;
objcollection.value.push(item_obj);
count++;
});
return objcollection;
},
{
out:'productmapreduce'
}
);
当我监视终端上的mongod时,会显示一条消息
命令:mapReduce {$ msg:"查询不记录(太大)" } keyUpdates:0 numYields:264 keys(micros)W:3097 r:7111563 w:769188 reslen:140 5749ms