使用加扰字符串查询查找文档

时间:2018-06-11 16:40:57

标签: python mongodb

有没有办法找到一个与输入字符串中至少有一个字段值匹配的文档?就像我查询HelLo wOrD一样,那么数据库中至少包含helloword或两者的值都将作为结果返回?

集合

[{"title": "Word is a new hello"},
 {"title": "Hello There!"},
 {"description": "A new word is there."}]

脚本

i = "HelLo wOrD"
db.article.find({
            "$or": [
                {"title": {"$regex": i, "$options": "i"}},
                {"description":   {"$regex": i, "$options": "i"}},
            ]
})

预期结果:

[{"title": "Word is a new hello"},
 {"title": "Hello There!"},
 {"description": "A new word is there."}]

0 个答案:

没有答案