如何将运算符all和icontains的用法与mongoengine相结合 [英] How to combine the usage of operator all and icontains for mongoengine
问题描述
对于mongoengine,有运算符 all
和 icontains
。但是如何结合它们的使用呢?
For mongoengine, there are operators all
and icontains
. But how can I combine the usage of them?
对于每个项目,我只想与 icontains
匹配,而不是 / code>?我试图使用正则表达式。我工作,但不幸的是,如果我在mongoengine的查询中有多于1个
Q
因为它会尝试 deepcopy
模式
对象,但不幸的是 pattern
对象不能深入复制。
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.
推荐答案
实际上,我建议使用 pymongo ,通过 easy_install pymongo
安装,在pymongo中,您可以尝试:
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'}}
]})
这里, $ ne
和 $和
是本机mongo db运营商,您可以找到更多详细信息 mongodb advnace查询
here, $ne
and $and
are native mongo db operators, you could find more details mongodb advnace query
这篇关于如何将运算符all和icontains的用法与mongoengine相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!