Пример MongoDB для Yesod / Persistent

Хаскель и Йесод новичок здесь. Я пытался следовать примеру интеграции с Yesod из главы «Постоянные» в книге «Yesod» (http://www.yesodweb.com/book/persistent). Sqlite компилируется и работает нормально, кажется. Однако я пытаюсь использовать MongDB и с трудом заставляю вещи работать. В частности:

In the example for sqlite:

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist|

The Yesod book says "Mongo code will use mongoSettings instead." But I can't find it in any of the modules, and the code doesn't compile. So instead, I had to use this instead of mongoSettings:

MkPersistSettings { mpsBackend = ConT ''Action }

I had to import Language.Haskell.TH.Syntax to get it to compile, which I'm assuming should be hidden from the user so I'm certainly not doing it right.

Also, I found that in the Persistent tests for Mongo do without the "share" and "migrate" part. I'm actually not sure why, I'm guessing it's because MongoDB is Schema-less and doesn't need migration?

SqlPersist

I thought MongoPersist would be the counterpart to SqlPersist, and I guess it almost is--I found one instance of MongoPersist in the init.hs in the test directory of Persistent. But it's commented out, so I have a feeling it's obsolete? Otherwise it's not defined anyway as far as I can tell. So I don't know how to convert the following line (P.115 of the Yesod book, or near the end of http://www.yesodweb.com/book/persistent) to work for MongoDB:

instance YesodPersist PersistTest where
    type YesodPersistBackend PersistTest = SqlPersist
    runDB action = do
        PersistTest pool <- getYesod
        runSqlPool action pool

Using withMongoDBConn

So for sqlite, the code is (1st example from the webpage above):

main :: IO ()
main = withSqliteConn ":memory:" $ runSqlConn $ do
    runMigration migrateAll
    johnId <- insert $ Person "John Doe" $ Just 35
    ... and so on

But

main :: IO()
main = withMongoDBConn ":memory:" $ runMongoDBConn $ do
    runMigration migrateAll 
    johnId <- insert $ Person "John Doe" $ Just 35
    ... and so on          

не работает. Прежде всего,runMigration по какой-то причине не входит в объем. Хорошо, может быть, мне не нужна миграция для MongoDB, поэтому я убрал эту строку. Затем компилятор жалуется: Couldn't match expected typeAccessMode & APOS; с фактическим типомm0 b0' Expected type: m0 t0 -> (t0 -> m0 b0) -> AccessMode Actual type: m0 t0 -> (t0 -> m0 b0) -> m0 b0 и так далее. И на этом этапе моего самого беглого знания монад просто недостаточно, чтобы понять это.

В общем, мне очень трудно преобразовать пример интеграции с Yesod из книги Sqlite в MongoDB. Может ли кто-нибудь предоставить мне конкретный пример Yesod / Persistent с MongoDB? Большое спасибо заранее.

Ответы на вопрос(2)

Ваш ответ на вопрос