我正在尝试向Mongodb查询包含通过表单传递的部分标题的文档。
(defn findmovie
"Find movie by query"
[query]
(def search (str "#.*" (url-decode query) ".*"))
(println search)
(def movies (m/fetch :movie :where {:name {:$regex search}}))
(println movies)
(returnall movies)
)
query
这是一个参数。无论我输入什么内容,上面的代码都会返回空集合()
。
:name
中Gladiator (2000)
的示例值:name
和:where
中的#.*gladiator.*
类似{{1}}
答案 0 :(得分:1)
尝试直接传递正则表达式:
(defn findmovie
"Find movie by query"
[query]
(let [search (re-pattern (str ".*" (url-decode query) ".*"))
movies (m/fetch :movie :where {:name search})]
(returnall movies)))