在 MongoDB 中通过 PHP 调用存储过程 [英] Calling a stored procedure via PHP in MongoDB

查看:49
本文介绍了在 MongoDB 中通过 PHP 调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有可以提供帮助的人,

Dear everybody who can help,

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

I have this PHP > MongoDB problem, I want to call a stored procedure (stored in db.system.js collection) via PHP.

我没有参数,只有一个返回的 JSON 对象,如下所示:

I have no parameters, only a returning JSON object which looks like this:

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

它在数据库服务器的 shell 中运行良好,但是当我尝试通过 PHP 驱动程序调用它时,它只是不说"任何事情......

It works good in the shell on the database server, but when I try to call it via the PHP driver it just doesn't "say" anything...

我的代码如下所示:

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

我也尝试过这样使用:

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

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

Please help, I've got stuck on this one... I only want to call that sh*t after updating the collection...

先谢谢你,乙

推荐答案

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

Are you sure you're using the same database? Try simplifying it to a basic example, e.g.,

$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
)

这篇关于在 MongoDB 中通过 PHP 调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆