[英]Using pymongo/mongodb to filter based on multiple conditions including and/or?
我在 Zeppelin 笔记本中使用带有餐厅数据库的 pymongo 教程。
我曾尝试同时使用 $or/$and 语句,但我不断收到错误消息
%mongodb
db.resturants.find({$and :[{"cuisine": {$regex: "Pizza"}},
{"grades.grade" : {$ne: "A"}},
{"grades.grade" : {$ne: "B"}},
{"grades.grade" : {$ne: "C"}}]},
{$or : [{"cuisine": {$regex: "Pizza"}},
{"grades.score" : {$gt: 19}}]}).table()
您需要为运算符使用字符串:
db.resturants.find({"$and" :[{"cuisine": {$regex: "Pizza"}},
{"grades.grade" : {$ne: "A"}},
{"grades.grade" : {$ne: "B"}},
{"grades.grade" : {$ne: "C"}}]},
{"$or" : [{"cuisine": {$regex: "Pizza"}},
{"grades.score" : {$gt: 19}}]}).table()
您的语法在 MongoDB 中有效,但 pymongo 必须使用字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.