Guest User

Untitled

a guest
Jun 13th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. {-# LANGUAGE OverloadedStrings #-}
  2.  
  3. import Database.MongoDB
  4. import Data.UString (u)
  5. import Control.Monad.Trans (liftIO)
  6.  
  7. main = do
  8. ee <- runNet $ do
  9. conn <- connect (host "127.0.0.1")
  10. runConn run conn
  11. return ()
  12.  
  13. run = useDb "tailing" $ do
  14. createCollection [Capped, MaxByteSize (1024*1024)] "messages"
  15. insert "messages" ["by" =: u"me", "body" =: u"hello world!"]
  16. cur <- find (select [] "messages") {options = [TailableCursor, AwaitData, NoCursorTimeout]}
  17. monitor cur
  18.  
  19. monitor c = do
  20. doc <- next c
  21. liftIO (putStrLn . show $ doc)
  22. monitor c
  23.  
  24.  
  25. -- $ runhaskell tailing.hs
  26. -- Just [ _id: Oid 4c8d42f3 7a23b03c35000000, by: "me", body: "hello world!"]
  27. -- tailing.hs: server returned empty batch but says more results on server
Add Comment
Please, Sign In to add comment