2011-02-12 43 views

回答

28

请尝试使用python正则表达式对象。 Pymongo会正确地序列化它们:

import re 
config.gThingCollection.find({"name": re.compile(regex, re.IGNORECASE)}) 
17

您可以在查询中使用MongoDB正则表达式选项。

config.gThingCollection.find({"name":{"$regex":regex, "$options": "-i"}}) 
1
res = posts.find({"geography": {"$regex": 'europe', "$options": 'i'}}) 

# if you need use $not 
import re 
res = posts.find(
    {"geography": {"$not": re.compile('europe'), "$options": 'i'}})