Call Mongodb stored function from PHP7

倖福魔咒の 提交于 2021-02-18 03:19:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!