Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
21 lines (15 sloc) 1022 Bytes

persistent-mongoDB has extended to support the most commonly used MongoDB operators in a type-safe way. However, you still may need to use the raw driver with Persistent at times. Note also that persistent-mongoDB exposes functions to help with converting between a document and an entity: toInsertFields, entityToFields, docToEntityEither, and docToEntityThrow.

Persistent's test case

runDB is still the MongoDB Action monad, so just run MongoDB queries as normal.

import Database.MongoDB((=:))
import Database.MongoDB (Document, Action, findOne)
import qualified Database.MongoDB as MongoDB

rawOne :: Trans.MonadIO m => MongoDB.Collection -> MongoDB.Selector -> Action m (Maybe Document)
rawOne collection q = findOne ( q collection)

theCollection :: Trans.MonadIO m
theCollection = rawOne $ "collection-name"

getTheR theId = do
  Just doc <- runDB $ theCollection ["_id" =: theId]
You can’t perform that action at this time.