我们有一个 正则匹配的mongodb查询,查询pic_label不包含有冒号的记录,如下:
{"pic_label" : {"$not":/:/},"source":"guangxi"}
需要转换成pymongo的查询语句来查询,直接对应翻译成pymongo的语句如下:
def find_pic_structures():
pics = []
client = init_mongo_client()
db = client['my_pic']
collection = db['pic_structures']
queryArgs = {"pic_label": { "$not":{"$regex":":"}}, "source": "guangxi"}
searchRes = collection.find(queryArgs)
for x in searchRes:
pics.append(x)
print(x)
return pics
报错如下:
pymongo.errors.OperationFailure: $not cannot have a regex
完整报错如下:
/Users/zzq/workspace/myproject/venv/bin/python /Users/zzq/workspace/myproject/my_project/dao/pic_action.py
启动环境 dev
mongodb://127.0.0.1:27017
Tracebac