0
在持久化的SQL版本中,似乎直接訪問SQL是通過rawSql
完成的。有沒有類似的方式來訪問mongoDB後端的低級命令?有沒有辦法從persistent-mongoDB使用低級mongoDB後端?
在持久化的SQL版本中,似乎直接訪問SQL是通過rawSql
完成的。有沒有類似的方式來訪問mongoDB後端的低級命令?有沒有辦法從persistent-mongoDB使用低級mongoDB後端?
事實證明,這比我想象的要容易得多。只需導入Database.MongoDB
並使用runDB中的原始驅動程序命令。例如:
import Database.MongoDB
...
postCommentR :: DocumentId -> Handler Value
postCommentR documentId = do
comment <- commentOr400
let idString = toPathPiece documentId
contents = commentBody comment
runDB $ DB.modify (DB.select ["_id" DB.=: idString] "Document") ["$push" DB.=: ["comments" DB.=: contents]]
returnJson $ object []
的[MongoDB的示例耶索德/持久性]
可能重複(http://stackoverflow.com/questions/11731953/mongodb-example-for-yesod-persistent) – iamnat 2014-09-04 23:43:31
我不認爲這是一個重複的另一個問題不談論使用MongoDB的直接API。 – 2014-09-05 21:00:08