我在控制台中使用了一个相当长的MongoDB查询:
db.addresses.find({
$and: [ {"date": {$gte: "2017-06-01"}},
{"date": {$lt: "2017-06-60"}},
{ $or: [{"address.postal_code" : { $regex: /^SW1 /i } },
{"address.postal_code" : { $regex: /^SW2 /i } },
{"address.postal_code" : { $regex: /^SW3 /i } },
{"address.postal_code" : { $regex: /^SW4 /i } }
]}
]})
我现在需要用PyMongo在Python中使用它,但可以理解的是:
SyntaxError: invalid syntax
由于它相当复杂,有没有一种简单的方法来逃避它,因为我有几个方法可以使用,我尝试将上面的查询封装成这样:
"""The query from above between the brackets"""
addresses_to_process = db.addresses.find(query)
但我有个错误:
TypeError: filter must be an instance of dict, bson.son.SON, or other type that inherits from collections.Mapping
目前没有回答
相关问题 更多 >
编程相关推荐