您好,我要做的就是获取每个不同部门类型的计数:
fnMap = function() {
emit(this.departments.departmentType, {typeCount:1} );
}
fnReduce = function(key, values) {
var result = {typeCount: 0};
values.forEach(function(value) {
result.typeCount += value.brandCount;
});
return result;
};
var command = {
mapreduce : "clients",
query : {"departments.departmentType": {$exists: true}},
map : fnMap.toString(),
reduce : fnReduce.toString(),
//sort: {"departments.departmentType":1},
out: {inline: 1}
};
mongoose.connection.db.executeDbCommand(command, function(err, dbres) {
});
执行该命令时,dbres.documents[0].results 仅包含一项具有部门类型总数的项,而不是每个部门类型一项及其计数的多项。
任何想法我做错了什么?
此外,当我取消注释 SORT 行时,我收到错误“db assertion failure: could not create cursor over...”,我相信字段名称写正确。