Gareth Charnock
Gareth Charnock

Reputation: 1166

Is there a way to use the low level mongoDB backend from persistent-mongoDB?

In the SQL version of persistent it appears that direct access to SQL is done with rawSql. Is there a similar way to access low level commands from the mongoDB backend?

Upvotes: 0

Views: 78

Answers (1)

Gareth Charnock
Gareth Charnock

Reputation: 1166

It turns out to be much easier than I thought. Just import Database.MongoDB and use the raw driver commands inside runDB. Example:

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 []

Upvotes: 1

Related Questions