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

编程入门 行业动态 更新时间:2024-10-07 20:32:58
本文介绍了在 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 调用存储过程

本文发布于:2023-10-19 01:52:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506036.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   MongoDB   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!