-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read.hs
37 lines (26 loc) · 839 Bytes
/
Read.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules, NoMonomorphismRestriction #-}
import Database.MongoDB
import Control.Monad.Trans (liftIO)
main = do
pipe <- connect (host "127.0.0.1")
e <- access pipe master "social" run
close pipe
-- >>= :: (Monad m) => ma -> (a -> mb) -> mb
-- Monad: Action IO
-- a: [Document]
run :: Action IO ()
run = do
allTeams >>= printDocs "All Teams"
allTeams :: Action IO [Document]
allTeams = do
cursor <- find (select [] "stream")
enum cursor
enum :: Cursor -> Action IO [Document]
enum cursor = nextBatch cursor >>= \res -> case res of
[] -> return []
xs -> do
future <- enum cursor
return (xs ++ future)
printDocs :: String -> [Document] -> Action IO ()
printDocs title docs = liftIO $ putStrLn title >> mapM_ (print . include ["_id"]) docs
enum :: Cursor ->