如何在 pymongo 中使用 mongo 函数? [英] How can I use mongo functions in pymongo?

查看:54
本文介绍了如何在 pymongo 中使用 mongo 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看 mongodb 教程.我想使用一些 javascript mongodb 函数,但我看不到如何用 pymongo 做到这一点.我可以启动 mongo shell,但这必须通过 pymongo 作为我的 wsgi 应用程序的一部分来完成.

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 似乎有 代码 对象 - 我如何 1)将一些 Code 对象放入我的数据库中,以及 2)将它们与 pymongo 一起使用?

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

推荐答案

任何想要在服务器上运行的 JavaScript 函数都必须通过 "eval" 命令.

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

你可以看到如何从 Python 中调用它 这里.

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.

一般来说,eval"的性能会很差,如果您正在编写 Python 应用程序,我建议您在 Python 中实现您计划在 JS 中实现的任何内容.这是最近讨论比较的一个问题:MongoDBdb.eval() 在 javascript shell 与 pymongo 中的性能

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

这篇关于如何在 pymongo 中使用 mongo 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆