Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE OverloadedStrings #-}
- import Database.MongoDB
- import Data.UString (u)
- import Control.Monad.Trans (liftIO)
- main = do
- ee <- runNet $ do
- conn <- connect (host "127.0.0.1")
- runConn run conn
- return ()
- run = useDb "tailing" $ do
- createCollection [Capped, MaxByteSize (1024*1024)] "messages"
- insert "messages" ["by" =: u"me", "body" =: u"hello world!"]
- cur <- find (select [] "messages") {options = [TailableCursor, AwaitData, NoCursorTimeout]}
- monitor cur
- monitor c = do
- doc <- next c
- liftIO (putStrLn . show $ doc)
- monitor c
- -- $ runhaskell tailing.hs
- -- Just [ _id: Oid 4c8d42f3 7a23b03c35000000, by: "me", body: "hello world!"]
- -- tailing.hs: server returned empty batch but says more results on server
Add Comment
Please, Sign In to add comment