问题
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