我有一个包含以下字段的集合:
TestTable
{
"ID"
"Name"
"Ver"
"Serial"
"DateTime"
"FeatureID"
"FeatureName"
}
我想要一个 map reduce 函数来获取特定年份的记录数。我写的map reduce函数是:
map= function(){
year= Date.UTC(this.DateTime.getFullYear());
emit({year: year}, {count: 1});
}
reduce= function(key, values){
var count=0;
for(v in values){
count+= v['count'];
});
return {count: count};
}
现在输出应该给出每年的文件数。map reduce 函数是否正确?
我得到的结果是:
> db.Years.find()
{ "_id" : { "year" : NaN }, "value" : { "count" : NaN } }
> db.Years.find().count()
1
这不是我所期望的。
已编辑
TestTable 文件之一:
> db.TestTable.findOne()
{
"_id" : ObjectId("527c48e99000cf10bc2a1d82"),
"ID" : "LogID16587",
"Name" : "LogName15247",
"Ver" : "VersionID11",
"Serial" : "ProductID727",
"DateTime" : ISODate("1998-12-15T18:30:00Z"),
"FeatureID" : "FeatureID465",
"FeatureName" : "FeatureName 1460"
}
提前致谢。