Reputation: 1149
Dear everybody who can help,
I have this PHP > MongoDB problem, I want to call a stored procedure (stored in db.system.js collection) via PHP.
I have no parameters, only a returning JSON object which looks like this:
{"archived":[the number of the archived messages]}
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...
My code looks like this:
$DB->execute(
new MongoCode(
"function () { return archiveMessages(); }"
)
);
I have also tried to use somehow like this:
$DB->execute("archiveMessages()");
Please help, I've got stuck on this one... I only want to call that sh*t after updating the collection...
Thank you in advance, B
Upvotes: 2
Views: 2175
Reputation: 23592
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()"));
Results in:
Array
(
[retval] => 3
[ok] => 1
)
Upvotes: 4
Reputation: 24007
Check the documentation:
http://php.net/manual/en/mongodb.execute.php
Are you assigning the return value of execute() to a variable?
Upvotes: 1