我想返回那些必须同时满足 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/