优化Mongodb查询

时间:2015-09-22 07:03:56

标签: mongodb mapreduce mongodb-query aggregation-framework

db.runCommand({
    'mapreduce': 'rtb_ymantnt_xyz',
    'map': 'function() { var band_size = 0.5; var cscsm_id = this.cscsm_id;var site_id =this.entity_id;var tld=this.domain_id;
    this.xyz.forEach(function(h) {
        var converted_sum_cpm = h.sum_cpm;
        var bin_start = Math.floor(converted_sum_cpm / h.bin_volume / band_size) * band_size;
        emit({
            site_id: site_id,
            tld: tld,
            bin: bin_start
        }, {
            sum_cpm: h.sum_cpm,
            bin_volume: h.bin_volume,
            band_size: band_size
        })
    })
    }
    ',
    'reduce': 'function(key, values) { var result = {sum_cpm : 0, bin_volume : 0 , band_size : 0};
    values.forEach(function(value) {
    result.sum_cpm += value.sum_cpm;
    result.bin_volume += value.bin_volume;
    result.band_size = value.band_size;
    });
    return result;
}
',
'verbose': true,
'query': {
    'entity_reference_id': 43568,
    'date': {
    '$gte': '2015-06-15',
    '$lte': '2015-06-15'
    },
    'entity_type': 1,
    'domain_id': {
    '$ne': -1
    },
    'cscsm_id': {
    '$ne': -1
    },
    'bid_type': 1
},
'out': {
    'replace': 'xyz_debug_anmsyo'
}
})

db.xyz_debug_anmsyo.find().forEach(function(x) {
    print(x._id.site_id + "," + x._id.tld + "," + x._id.bin + "," + x.value.bin_volume + "," + x.value.sum_cpm)
})

有人可以建议优化这个mongo查询。

0 个答案:

没有答案