Connect to a single server or a replica set of servers
- type IOE = ErrorT IOError IO
- runIOE :: ErrorT IOError IO a -> IO a
- type Pipe = Pipeline Response Message
- close :: Pipeline i o -> IO ()
- isClosed :: Pipeline i o -> IO Bool
- data Host = Host HostName PortID
- data PortID
- defaultPort :: PortID
- host :: HostName -> Host
- showHostPort :: Host -> String
- readHostPort :: String -> Host
- readHostPortM :: Monad m => String -> m Host
- connect :: Host -> IOE Pipe
- type ReplicaSetName = UString
- openReplicaSet :: (ReplicaSetName, [Host]) -> IOE ReplicaSet
- data ReplicaSet
- primary :: ReplicaSet -> IOE Pipe
- secondaryOk :: ReplicaSet -> IOE Pipe
- closeReplicaSet :: ReplicaSet -> IO ()
Util
runIOE :: ErrorT IOError IO a -> IO aSource
Run action while catching explicit error and rethrowing in IO monad
Connection
Server
Default MongoDB port = 27017
host :: HostName -> HostSource
Host on defaultPort
showHostPort :: Host -> StringSource
Display host as "host:port" TODO: Distinguish Service and UnixSocket port
readHostPort :: String -> HostSource
Read string "hostname:port" as Host hostname (PortNumber port)
or "hostname" as host hostname
(default port). Error if string does not match either syntax.
readHostPortM :: Monad m => String -> m HostSource
Read string "hostname:port" as Host hosthame (PortNumber port)
or "hostname" as host hostname
(default port). Fail if string does not match either syntax.
TODO: handle Service and UnixSocket port
connect :: Host -> IOE PipeSource
Connect to Host returning pipelined TCP connection. Throw IOError if problem connecting.
Replica Set
type ReplicaSetName = UStringSource
openReplicaSet :: (ReplicaSetName, [Host]) -> IOE ReplicaSetSource
Open connections (on demand) to servers in replica set. Supplied hosts is seed list. At least one of them must be a live member of the named replica set, otherwise fail.
data ReplicaSet Source
Maintains a connection (created on demand) to each server in the named replica set
primary :: ReplicaSet -> IOE PipeSource
Return connection to current primary of replica set. Fail if no primary available.
secondaryOk :: ReplicaSet -> IOE PipeSource
Return connection to a random secondary, or primary if no secondaries available.
closeReplicaSet :: ReplicaSet -> IO ()Source
Close all connections to replica set