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();

$avgresult=$avgresult->getNext();

print_R($avgresult);

//$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' ";

//$stn=fetch_row($query);

//$stn1=round($stn['stn1'],2);

//$stn2=round($stn['stn2'],2);

//var_dump($stn1nr);

$stn1nr = $avgresult['ch1avg'];

$stn2nr = $avgresult['ch2avg'];

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

var_dump($stn1nr);

$stn1=round($stn1nr,2);

$stn2=round($stn2nr,2);

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 comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.