问题
Below is my mongodb function that is stored in Mongodb.
db.system.js.save(
{
_id: "echoFunction",
value : function(x) { return x; }
}
)
I can call this function in mongo using below query :
db.loadServerScripts();
echoFunction(3);
Now i want to call this function from PHP 7. and also help with laravel.
回答1:
You can use following code snippet from laravel to execute your mongoDB function.
$cursor = DB::connection('mongodb')->command(array('eval' => 'echoFunction("4")'));
$data = $cursor->toArray();
dd($data);
Try and let me know if it works.
来源:https://stackoverflow.com/questions/42088817/call-mongodb-stored-function-from-php7