有一个MongoDB文档:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://contmgmt.ecm.omega/WorkspaceManager/ChipDataJob"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://contmgmt.ecm.omega/WorkspaceManager/ChipDataJob">
<wsdl:types>
<xsd:schema
targetNamespace="http://contmgmt.ecm.omega/WorkspaceManager/ChipDataJob"
xmlns:tns="http://contmgmt.ecm.omega/WorkspaceManager/ChipDataJob"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="qualified">
<xsd:include schemaLocation="ChipDataJob.xsd" />
</xsd:schema>
</wsdl:types>
<!-- Chip Message -->
<wsdl:message name="dataChipperJob">
<wsdl:part name="job" element="tns:ChipJob" />
</wsdl:message>
<wsdl:message name="dataChipperResponse">
<wsdl:part name="taskId" element="xs:long" />
</wsdl:message>
<wsdl:message name="cancelResponse">
<wsdl:part name="cancelSuccess" element="xs:boolean" />
</wsdl:message>
<wsdl:portType name="DataChipperServicePort">
<wsdl:operation name="submitRequest">
<wsdl:input message="tns:dataChipperJob"/>
<wsdl:output message="tns:dataChipperResponse"/>
</wsdl:operation>
<wsdl:operation name="cancelRequest">
<wsdl:input message="tns:dataChipperResponse"/>
<wsdl:output message="tns:cancelResponse"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
如何使用MapReduce计算子文档对象中的项目数.obj_id,每个event_type的总数? 聚合框架因大量数据而无法使用,结果大于16MB。
有什么想法吗?
答案 0 :(得分:1)
要计算给定objects.obj_id
的所有子文档item_type
的项目数,您只需要在map step中发出数组长度。并将该值与您的event_type
相关联。 reduce step是一个简单的总和:
map = function() {
emit(this.event_type, this.objects.obj_id.length)
}
reduce = function(key, values) {
return values.reduce(function(a,b) { return a+b})
}
鉴于您的样本数据,这将产生:
> db.test.mapReduce(map,dummy, {out:{inline:1}}).results
[ { "_id" : "s", "value" : 6 } } ]