Saturday 31 August 2013

i want to now about mapreduce in mongodb codeigniter

i want to now about mapreduce in mongodb codeigniter

here am basically performing group by operation
table:sale_announcement_history fields:history_timestamp,logged by,
sale_annoucement_id --- want to know max timestamp and distinct logged by
of a particular sale_id
function test_map_reduce(){
$map = new MongoCode('
function(){
var total = 0;
var maxx = 0;
var unique = 0;
for (sum in this.sale_announcement_id) {
$total += this.sale_announcement_id[sum];
}
for (max in this.history_timestamp) {
maxx = this.history_timestamp[max];
}
for (distinct in this.logged_by) {
unique = this.logged_by[distinct];
}
emit(this.sale_announcement_id,{total:total,max:maxx,unique:unique});
}
');
$reduce = new MongoCode('
function(key, values){
var result = {total: 0, max: 0, unique: 0};
values.forEach(function(v) {
result.total = v.total;
result.max = v.max;
result.unique = v.unique;
});
return result;
}
');
$result = $this->mongo_db->command(array(
'mapreduce'=>"sale_announcement_history", // <= 'mtb'
'road' 'minivelo'
'map'=>$map,
'reduce'=>$reduce,
//'query'=>array(),
'out'=> 'test_res1'));
echo'<pre>';
print_r($result);
}

No comments:

Post a Comment