当数据是mongodb中的url时,正则表达式查找查询不起作用

时间:2019-02-14 16:41:31

标签: python mongodb pymongo

我的网址字段为:

db.test.insert({"url":"https://www.google.com/shopping/product/1/online?prds=pid:11247610123343072928,https://www.google.com/shopping/product/1/online?prds=pid:1124761012334307256565"})

但是当我这样做

db.test.find({"url": {"$regex":"https://www.google.com/shopping/product/1/online?prds=pid:11247610123343072928"}})

它什么也不返回。我想找到与子字符串匹配的所有文档。我在做什么错了?

1 个答案:

答案 0 :(得分:2)

您只需要忽略特殊字符,然后您的查询即可使用。 尝试在下面使用查询:

db.test.find({"url": {"$regex":"https://www.google.com/shopping/product/1/online.*\\?.*prds=pid:11247610123343072928"}})