Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 有没有办法从持久化mongoDB使用低级mongoDB后端?_Haskell_Yesod - Fatal编程技术网

Haskell 有没有办法从持久化mongoDB使用低级mongoDB后端?

Haskell 有没有办法从持久化mongoDB使用低级mongoDB后端?,haskell,yesod,Haskell,Yesod,在persistent的SQL版本中,直接访问SQL似乎是通过rawSql完成的。是否有类似的方法从mongoDB后端访问低级命令?结果比我想象的要简单得多。只需导入Database.MongoDB并在runDB中使用原始驱动程序命令。例如: import Database.MongoDB ... postCommentR :: DocumentId -> Handler Value postCommentR documentId = do comment <- commentO

在persistent的SQL版本中,直接访问SQL似乎是通过
rawSql
完成的。是否有类似的方法从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 []
import Database.MongoDB
...
postCommentR::DocumentId->处理程序值
postCommentR documentId=do

注释可能的重复我不认为这是重复的,因为另一个问题并没有提到使用MongoDB的DirectAPI。