mongodb php - PHP Mongo:command not found -


i have been trying use mongo::command in php build mapreduce every time run code following error: php fatal error, call undefined method "mongo:command"

my code:

try {     $map = new mongocode("function() {                     if (!this.tags) {                         return;                     }                      (index in this.tags) {                         emit(this.tags[index], 1);                     }");     $reduce = new mongocode("function(previous, current) {                                 var count = 0;                                  (index in current) {                                    count += current[index];                                  }                                  return count;                             }");     $tags = $this->db->command(array(         //line error found on              "mapreduce" => "blog",               "map" => $map,              "reduce" => $reduce));     $con=$this->db->selectcollection($tags['result'])->find();     var_dump($con); } catch(mongocursorexception $e) {     echo "error message: ".$e->getmessage()."\n";     echo "error code: ".$e->getcode()."\n"; } 

please note $this->db refers connection (previously defined) , blog collection.

for reference have used: http://php.net/manual/en/mongodb.command.php

the os use ubuntu 12.04 , i've double checked both php.ini files both include mongo.so - can normal queries mongodb inserting , fetching data, command seems not work.

do select collection $d = $m->demo;

php.net:

<?php $m = new mongoclient(); $d = $m->demo; $c = $d->poiconcat;  $r = $d->command(array( 'geonear' => "poiconcat",      // search in poiconcat collection 'near' => array(-0.08, 51.48), // search near 51.48°n, 0.08°e 'spherical' => true,           // enable spherical search 'num' => 5,                    // maximum 5 returned documents )); print_r($r); ?> 

i think in code didn't select collection $d = $this->db->demo; put collection name instead of demo

try {     $map = new mongocode("function() {                 if (!this.tags) {                     return;                 }                  (index in this.tags) {                     emit(this.tags[index], 1);                 }");     $reduce = new mongocode("function(previous, current) {                             var count = 0;                              (index in current) {                                count += current[index];                              }                              return count;                         }");      $d = $this->db->demo;// attention       $tags = $d->command(array(         //line error found on          "mapreduce" => "blog",           "map" => $map,          "reduce" => $reduce));      $con=$d->selectcollection($tags['result'])->find();      var_dump($con); } catch(mongocursorexception $e) {    echo "error message: ".$e->getmessage()."\n";    echo "error code: ".$e->getcode()."\n"; } 

edit sample:i sample see it

try {    $map = new mongocode("function() { emit(this.user_id,1); }");    $reduce = new mongocode("function(k, vals) { ".       "var sum = 0;".       "for (var in vals) {".          "sum += vals[i];".        "}".       "return sum; }");       $db=new mongo("mongodb://sepidar:123@localhost:27017/admin");                        $d = $db->sepidarsoft_cbms;// attention        $tags = $d->command(array(         //line error found on           'mapreduce'=>'runuser',           "map" => $map,           "reduce" => $reduce,           "out" => array('merge'=>'sepidarsoft_cbms', 'db'=> 'runuser')       ));       print_r($tags); } catch(mongocursorexception $e) {      echo "error message: ".$e->getmessage()."\n";      echo "error code: ".$e->getcode()."\n"; } 

my mongodb struct

result

 array (     [result] => array     (         [db] => runuser         [collection] => sepidarsoft_cbms     )      [timemillis] => 2     [counts] => array     (         [input] => 1         [emit] => 1         [reduce] => 0         [output] => 1     )      [ok] => 1 ) 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -