在MongoDB中通过PHP调用存储过程


Calling a stored procedure via PHP in MongoDB

尊敬的各位,

我有这个PHP>MongoDB的问题,我想通过PHP调用一个存储过程(存储在db.system.js集合中)。

我没有参数,只有一个返回的JSON对象,看起来像这样:

{"archived":[the number of the archived messages]}

它在数据库服务器上的shell中运行良好,但当我尝试通过PHP驱动程序调用它时,它什么都不"说"。。。

我的代码如下:

$DB->execute(
    new MongoCode(
        "function () { return archiveMessages(); }"
    )
);

我也尝试过这样使用:

$DB->execute("archiveMessages()");

请帮帮我,我被这个卡住了。。。我只想在更新集合后调用该sh*t。。。

提前感谢您,B

您确定使用的是同一个数据库吗?尝试将其简化为一个基本示例,例如

$m = new Mongo();
$db = $m->foo;
$db->system->js->save(array("_id"=>"archiveMessages", 
   "value"=>new MongoCode("function() { return 3; }")));
print_r($db->execute("archiveMessages()"));

结果:

Array
(   
    [retval] => 3
    [ok] => 1
)

检查文档:

http://php.net/manual/en/mongodb.execute.php

是否将execute()的返回值赋给变量?