PHP で mongo::command を使用して MapReduce を構築しようとしましたが、コードを実行するたびに次のエラーが発生します。PHP Fatal Error, call to undefined method "mongo:command"
私のコード:
try {
$map = new MongoCode("function() {
if (!this.tags) {
return;
}
for (index in this.tags) {
emit(this.tags[index], 1);
}");
$reduce = new MongoCode("function(previous, current) {
var count = 0;
for (index in current) {
count += current[index];
}
return count;
}");
$tags = $this->db->command(array( //Line the error is 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";
}
$this->db
私の接続 (以前に定義された) を指しblog
、コレクションであることに注意してください。
参考のために私が使用した:http://php.net/manual/en/mongodb.command.php
私が使用しているOSはUbuntu 12.04で、mongo.soを含む両方のphp.iniファイルを再確認しました-データの挿入やフェッチなど、mongodbで通常のクエリを実行できますが、コマンドだけが機能していないようです。