How can I use mongo functions in pymongo?

孤人 提交于 2019-12-10 10:53:14

问题


I'm looking at mongodb tutorials. I want to make use of some javascript mongodb functions, but I can't see how I can do this with pymongo. I can fire up mongo shell, but this has to be done via pymongo as a part of my wsgi app.

pymongo seems to have Code object - How can I 1)put some Code objects into my db, and 2)use them with pymongo?


回答1:


Any JavaScript functions you want to run on the server have to be executed with "eval" command.

You can see how to invoke that from Python here.

You can invoke functions you have stored on the server though it's not recommended.

In general, performance of "eval" will be poor and I would recommend implementing in Python anything you were planning on implementing in JS if you are writing a Python application. Here is a question with recent discussion of the comparison: MongoDB performance of db.eval() in javascript shell vs. pymongo



来源:https://stackoverflow.com/questions/16253318/how-can-i-use-mongo-functions-in-pymongo

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