Skip to content

Instantly share code, notes, and snippets.

@bluescreen303
Created September 12, 2010 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluescreen303/576461 to your computer and use it in GitHub Desktop.
Save bluescreen303/576461 to your computer and use it in GitHub Desktop.
{-# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment