Created
September 12, 2010 21:16
-
-
Save bluescreen303/576461 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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