2

pymongo 有没有办法使用字符串而不是字典来执行查询?我希望能够使用与 python/pymongo 的 MongoDB shell 完全相同的语法。那可能吗?

4

2 回答 2

1

The eval() function might be what you're looking for. Note that it executes the JS code on the db server -- NOT in a Mongo shell on some client. Therefore it comes with lots of warnings, and I would strongly advise against using it in a serious production situation. See the Mongo db.eval docs for details and examples.

于 2013-01-19T23:47:24.237 回答
1

MongoDB shell 是功能齐全的 javascript 控制台/解释器,带有一些与 mongodb 服务器的消息绑定。相比之下,PyMongo 缺少嵌入式 javascript 解释器甚至 javascript 解析器,因此您无法按原样执行 MongoDB shell 查询。

请注意,mongo shell 查询不是 json 文档,因为它们能够包含一些函数和一些对象构造函数,例如{value: 2+2}.

于 2013-01-19T22:00:18.767 回答