2024-04-18 23:32:44 发布
网友
如何指定REGEX并忽略大小写:
regex = ".*" + filter + ".*"; config.gThingCollection.find({"name":{"$regex":regex}})
我希望过滤器不区分大小写,如何实现?
您可以在查询中使用MongoDB regex选项。
config.gThingCollection.find({"name":{"$regex":regex, "$options": "-i"}})
您的代码应该如下所示:
regex = ".*" + filter + ".*"; config.gThingCollection.find({"name":{"$regex":regex, "$options":"i"}})
引用:http://docs.mongodb.org/v2.2/reference/operator/regex/
尝试改用python正则表达式对象。Pymongo将正确序列化它们:
import re config.gThingCollection.find({"name": re.compile(regex, re.IGNORECASE)})
您可以在查询中使用MongoDB regex选项。
您的代码应该如下所示:
引用:http://docs.mongodb.org/v2.2/reference/operator/regex/
尝试改用python正则表达式对象。Pymongo将正确序列化它们:
相关问题 更多 >
编程相关推荐