2

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

2 Answers 2

4

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
)
Sign up to request clarification or add additional context in comments.

4 Comments

I am using the same DB, it's a constant. Just like almost anything else. This is the only thing I can't do now.
Can you print_r the result you're getting? [retval] => null?
I get an "Error 500: Internal Server Error". My PHP driver seems to work okay, does everything I ask from it.
That's from your app server, not MongoDB. Can you write a test script and just run it through PHP cli?
1

Check the documentation:

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

Are you assigning the return value of execute() to a variable?

1 Comment

Yes, I have been even checking the returning values... I needed that number I have mentioned above for displaying...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.