我有一个map-reduce查询,“工作”,做我想要的,但我迄今非常失败,使用我的输出数据,因为我不能锻炼如何阅读回来......让我解释一下......这里是我的EMIT:Mongo map-reduce输出,如何读取结果回来?
emit({ jobid: this.job_id, type: this.type}, { count: 1 })
和减少功能:
reduce: function (key, values) {
var total = 0;
for(i = 0; i < values.length; i++) {
total += values[i].count;
}
return { jobid: this.job_id, type:this.type, count: total};
},
它的功能和输出I的结果获得集合看起来是这样的:
{ "_id" : { "jobid" : "5051ef142a120", "type" : 3 }, "value" : { "count" : 1 } }
{ "_id" : { "jobid" : "5051ef142a120", "type" : 5 }, "value" : { "count" : 43 } }
{ "_id" : { "jobid" : "5051f1a9d5442", "type" : 2 }, "value" : { "count" : 1 } }
{ "_id" : { "jobid" : "5051f1a9d5442", "type" : 3 }, "value" : { "count" : 1 } }
{ "_id" : { "jobid" : "5051f299340b1", "type" : 2 }, "value" : { "count" : 1 } }
{ "_id" : { "jobid" : "5051f299340b1", "type" : 3 }, "value" : { "count" : 1 } }
但是我该如何发出一个查询说,找到所有jobid条目“jobid”,而忽略了类型?我试过这个问题,期待两行输出,但没有!
db.mrtest.find({ "_id": { "jobid" : "5051f299340b1" }});
我也曾尝试与失败:
db.mrtest.find({ "_id": { "jobid" : "5051f299340b1" }});
,并同时:
db.mrtest.find({ "_id" : { "jobid" : "5051f299340b1", "type" : 2 }})
不会产生输出一行的希望,再次改变这个不能产生任何东西:
db.mrtest.find({ "_id" : { "jobid" : "5051f299340b1", "type" : { $in: [2] }}})
我觉得你不能用_id字段来做这种事情,或者你可以吗?我想我需要重新组织我的先生的输出,但感觉就像失败了?!?!
帮助!
!PS:如果有人能解释为什么计数包含在所谓的 “价值” 领域,这也将是受欢迎的 “5051f299340b1”