How to combine the usage of operator all and icontains for mongoengine

丶灬走出姿态 提交于 2020-01-25 03:31:08

问题


For mongoengine, there are operators all and icontains. But how can I combine the usage of them?

Say for each item, I just want to match with icontains but not exact? I tried to use regex. I works but unfortunately it would break if I have more than 1 Q in the queryset of mongoengine. Because it would try to deepcopy the pattern object but unfortunately pattern object can't been copied deeply.


回答1:


actually, I recommend using pymongo, install by easy_install pymongo, in pymongo, you could try:

db.collections.find({'$and':[
    {'field A':re.compile('your pattern')},
    {'$ne':{'field A':'not exact word'}}
]})

here, $ne and $and are native mongo db operators, you could find more details mongodb advnace query



来源:https://stackoverflow.com/questions/11287001/how-to-combine-the-usage-of-operator-all-and-icontains-for-mongoengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!