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?
Asked
Active
Viewed 76 times
0

Gareth Charnock
- 1,166
- 7
- 17
-
possible duplicate of [MongoDB Example for Yesod / Persistent](http://stackoverflow.com/questions/11731953/mongodb-example-for-yesod-persistent) – iamnat Sep 04 '14 at 23:43
-
I don't think this is a duplicate as the other question doesn't talk about using the direct API for MongoDB. – Ganesh Sittampalam Sep 05 '14 at 21:00
1 Answers
1
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 []

Gareth Charnock
- 1,166
- 7
- 17