有没有办法找到一个与输入字符串中至少有一个字段值匹配的文档?就像我查询HelLo wOrD
一样,那么数据库中至少包含hello
或word
或两者的值都将作为结果返回?
[{"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."}]