python - 蒙戈 : combining AND and OR

标签 python mongodb pymongo database

我想返回那些必须同时满足 AND 和 OR 条件的记录。 AND 条件检查该值是否与集合外部的外部值匹配,然后检查它是否与一个或两个 OR 条件匹配。

这是我使用 pymongo 的查询:

 cursor = coll.find(
                { "$and" : [
                        {"term" : 1} == events, 
                        { "$or" : [
                                {"coordinates.type" : "Point"}, 
                                {"place.full_name" : {"$ne" : None}}
                        ]}
                    ]}, 
                           {"coordinates" : 1, "place.full_name" : 1}, 
                            tailable = True, timeout  = False )

我可以单独运行查询的 OR 部分。相反,我收到一条错误消息:

OperationFailure: database error: $and/$or elements must be objects

我是 Mongo 和 Python 新手。

非常感谢

最佳答案

该行无效:

{"term" : 1} == events

不确定这里的意图是什么,但如果您删除“==事件”,它应该是一个有效的查询参数

关于python - 蒙戈 : combining AND and OR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391238/

相关文章:

python - Pydrive:将文档导出为 html

php - 将 laravel jenssegers 连接到 mongodb atlas 集群

python - PyMongo 游标迭代

mongodb - 使用吗啡仅选择mongo db中的一列

node.js - MongoDB Node native 驱动程序创建重复文档

python - 将项目附加到 PyMongo 中的 MongoDB 文档数组而不重新插入

python - PyMongo upsert 抛出 "upsert must be an instance of bool"错误

python - Django 登录不工作。仅适用于 super 用户/管理员

python - python 中的循环优化

python - 从Django ORM中高效提取大量数据