【问题标题】:Mongo map-reduce output, how to read results back?Mongo map-reduce 输出,如何读回结果?
【发布时间】:2012-10-08 14:39:50
【问题描述】:

我有一个“有效”的 map-reduce 查询,它可以做我想做的事,但是到目前为止,我没有充分利用我的输出数据,因为我无法锻炼如何读回它……让我解释一下…… . 这是我的发射:

emit( { jobid: this.job_id, type: this.type}, { count: 1 })

还有reduce函数:

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};
},

它的功能和我在结果集合中得到的输出如下所示:

{ "_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 字段做这样的事情,或者你可以吗?我想我需要重新组织我的 mr 输出,但这感觉就像以某种方式失败?!?!

救命!

PS:如果有人能解释为什么计数包含在一个名为“值”的字段中,那也很受欢迎!“5051f299340b1”

【问题讨论】:

    标签: mongodb mapreduce


    【解决方案1】:

    你试过了吗:

    db.mrtest.find( { "_id.jobid": "506ea3a85e126" })
    

    这对我有用!

    【讨论】:

      【解决方案2】:
      db.mrtest.find( { "_id.jobid": "506ea3a85e126" })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        • 2014-06-02
        • 1970-01-01
        • 2023-03-23
        相关资源
        最近更新 更多