【发布时间】:2013-12-26 03:39:15
【问题描述】:
为了通过文本在 mongo 数据库中搜索项目,我需要根据 documentation 创建一个索引。
下面的代码创建了这个索引:
index is Index {iColl = "note", iKey = [ text: 1], iName = "text_1", iUnique = False, iDropDups = False}
为什么代码会出现这个错误?
*** Exception: expected "results" in [ ok: 0.0, errmsg: "no text index for: db.note"]
更新
以下更新的代码出现相同的错误。我改变的是我现在使用createIndex。
let order = [(fieldToText TextField) =: (1 :: Int32)]
docIndex = index (docTypeToText docType) order
actionResult <- run pipe dbName $ createIndex docIndex
case actionResult of
Left failure -> do putStrLn $ show failure
return []
Right () -> do
putStrLn $ "index is " ++ show docIndex
run pipe dbName $ ensureIndex docIndex
mDoc <- run pipe dbName $ runCommand
[pack "text" =: (docTypeToText docType),
pack "search" =: (pack $ unwords keywords),
pack "filter" =: (selector $ selection query)]
case mDoc of
Left failure -> do putStrLn $ show failure
return []
Right doc -> let Array results = valueAt (pack "results") doc
ds = [d | Doc d <- results]
in return ds
更新见下方评论。
【问题讨论】: