Jump to content

Mongo DB map reduce

Recommended Posts

Hello i need to converse a mysql db to mongo db but i have problems with getting my variables out of the map reduce, i keep getting a error on $experiments->update(array("qc" => array("stn1" => $stn1, "stn2" => $stn2))); this is the error Fatal error: Call to a member function update() on a non-object. Can someone please help me?


$map = new MongoCode("function() { emit(this.exp,{ch1: parseFloat(this.ch1_b), ch2: parseFloat

(this.ch2_b), count: 1 });}");

$reduce = new MongoCode (" function (key, vals){ var ret = { ch1: 0, ch2: 0, count: 0}; for(var i = 0; i <

vals.length; i++){ ret.ch1 += vals.ch1; ret.ch2 += vals.ch2; ret.count +=

vals.count;} return ret;}");

$finalize = new MongoCode("function(key, val){ val.ch1avg = (val.ch1 / val.count); val.ch2avg = (val.ch2 /

val.count); return val;}");

$result = $mongodb->command(array(

"mapreduce" => "features",

"map" => $map,

"reduce" => $reduce,

"finalize" => $finalize,

"query" => array("exp" => $experiment_id),

"out" => "features_averages"


$avgresult = $mongodb->features_averages->find();



//$stn = iterator_to_array($cursor);

//$query="SELECT avg(ch1_signal_to_background) as stn1, avg(ch2_signal_to_background) as stn2 FROM feature WHERE experiment_id=".$experiment_id." and chromosome >'0' and flag_m='0' ";





$stn1nr = $avgresult['ch1avg'];

$stn2nr = $avgresult['ch2avg'];

echo "---------------";




echo "---------------";

$experiments->update(array("qc" => array("stn1" => $stn1, "stn2" => $stn2)));


echo "<font color=\"#00cc00\">[".date("G:i:s")."] Signal to noise red {$stn1}<br>\r\n";

echo "[".date("G:i:s")."] Signal to noise green {$stn2}<br>\r\n";

Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.