我讨厌重新发布这些东西,但我觉得我输入的语法与我查找的大多数问题完全相同。我试图简单地计算价格大于 9000 的行数。有人可以告诉我我做错了什么吗?
var map1 = function(){
if(this.price > 9000) {
emit(this._id, {count: 1});
}
};
var red1 = function(keyId, values){
var count = 0;
values.forEach(function(v) {
count +=v['count'];
});
return{count: count};
}
db.plots.mapReduce(map1, red1, {out: "query1"})
我的结果是这样的......
> db.query1.find()
{ "_id" : ObjectId("5170609afa9e8646fc906815"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906816"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90681c"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906834"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90683e"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906846"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90684b"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90684e"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906851"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90685a"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906861"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906864"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906879"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906882"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906883"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90688b"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90688c"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906891"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc906894"), "value" : { "count" : 1 } }
{ "_id" : ObjectId("5170609afa9e8646fc90689a"), "value" : { "count" : 1 } }
我想要的是只取回一个号码。