【问题标题】:Is there a way to use the low level mongoDB backend from persistent-mongoDB?有没有办法使用persistent-mongoDB中的低级mongoDB后端?
【发布时间】:2014-09-04 20:27:42
【问题描述】:

在持久化的 SQL 版本中,对 SQL 的直接访问似乎是通过 rawSql 完成的。是否有类似的方法可以从 mongoDB 后端访问低级命令?

【问题讨论】:

标签: haskell yesod


【解决方案1】:

事实证明这比我想象的要容易得多。只需导入 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 []

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多