让我从数据样本开始:
{
"_id": {
"$oid": "5be18d5cedc30c3a396e3646"
},
"sex": "Male",
"first_name": "Anthony",
"last_name": "Nichols",
"job": "Internal Auditor",
"height": "162.68",
"weight": "68.37",
"birth_date": "2013-05-23T16:10:58Z",
"nationality": "Indonesia"
}
我正在尝试返回女性和男性的平均身高,这就是我的地图-reduce的样子:
var mapFunction1 = function() {
emit(this.sex, this.height);
};
var reduceFunction1 = function(keySex,valuesHeight) {
return Array.avg(valuesHeight);
};
db.people.mapReduce(
mapFunction1,
reduceFunction1,
{out:"example"}
)
结果我得到
{ "_id" : "Female", "value" : NaN }
{ "_id" : "Male", "value" : NaN }
例如,当我尝试求和而不是求平均值时,它只是打印出每个女性和男性的身高。我究竟做错了什么?你们能帮我吗?