0
我一直在嘗試使用蒙戈::命令在PHP構建的MapReduce但每次我的代碼運行時我得到以下錯誤:PHP Fatal Error, call to undefined method "mongo:command"
PHP蒙戈:找不到命令
我的代碼:
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
我使用的操作系統是Ubuntu的12.04,我仔細檢查過這兩個文件的php.ini其中既包括mongo.so - 我可以做正常的查詢,有喜歡的MongoDB插入和獲取數據,它只是命令似乎不起作用。
的分貝被選擇時,限定'$這 - > db'時。正如前面提到的,它適用於'$ this-> db-> blog-> find();' – Daniel 2013-05-04 15:20:52
你測試用'blog'替換'demo' – 2013-05-04 15:44:50
是的,我試過了,但是我得到了同樣的錯誤。我也許應該說'blog'不是數據庫,它是一個集合作爲數據庫的一部分。 – Daniel 2013-05-04 21:38:52