我希望使用这样的搜索模式从 clojure 访问 mongo db:
find({Keywords: /search-pattern/})
我有一个名为“soulflyer”的数据库,其中包含一个“图像”集合,每个成员都有一个“关键字”字段,其中包含来自它所代表的图像的 exif 关键字数组。要从 mongo java shell 中搜索我自己的图像,我这样做:
db.getCollection('images').find({Keywords: "Iain Wood"})
我得到一个包含关键字“Iain Wood”的所有条目的列表。如果我在 repl 中这样做,这在 clojure 中也可以正常工作:
(def connection (mg/connect))
(def db (mg/get-db connection "soulflyer"))
(seq (mc/find db "images" {"Keywords" "Iain Wood"}))
但是,我想搜索关键字的部分匹配。这在 java shell 中可以正常工作,使用如下命令:
db.getCollection('images').find({Keywords: /Iain/})
正如预期的那样,我用包含“Iain”的关键字取回了所有图像。但是我找不到如何从 clojure 进行这项工作。
(seq (mc/find db "images" {"Keywords" "/Iain/"}))
返回一个空列表
(seq (mc/find db "images" {"Keywords" /Iain/}))
(seq (mc/find db "images" {"Keywords" '/Iain/'}))
(seq (mc/find db "images" {"Keywords" \/Iain\/}))
(seq (mc/find db "images" {"Keywords" "\/Iain\/"}))
给我一个 LispReader$ReaderException 或冻结 repl。
如何让 clojure/monger 搜索简单的模式匹配?