allow individual ports to be set for connecting to cluster
This commit is contained in:
parent
6b64ef81d8
commit
613fc8ff6d
1 changed files with 13 additions and 10 deletions
|
@ -28,7 +28,7 @@ module Database.MongoDB
|
||||||
-- * Connection
|
-- * Connection
|
||||||
Connection,
|
Connection,
|
||||||
connect, connectOnPort, conClose, disconnect, dropDatabase,
|
connect, connectOnPort, conClose, disconnect, dropDatabase,
|
||||||
connectCluster, setTarget,
|
connectCluster, connectClusterOnPort, setTarget,
|
||||||
serverInfo, serverShutdown,
|
serverInfo, serverShutdown,
|
||||||
databasesInfo, databaseNames,
|
databasesInfo, databaseNames,
|
||||||
-- * Database
|
-- * Database
|
||||||
|
@ -94,23 +94,26 @@ connect = flip connectOnPort $ Network.PortNumber 27017
|
||||||
|
|
||||||
-- | Establish connections to a list of MongoDB servers
|
-- | Establish connections to a list of MongoDB servers
|
||||||
connectCluster :: [HostName] -> IO Connection
|
connectCluster :: [HostName] -> IO Connection
|
||||||
connectCluster [] = throwOpFailure "No hostnames in list"
|
connectCluster xs =
|
||||||
connectCluster xs = do
|
connectClusterOnPort $ fmap (flip (,) $ Network.PortNumber 27017) xs
|
||||||
c <- newConnection
|
|
||||||
connectAll c xs $ Network.PortNumber 27017
|
|
||||||
|
|
||||||
connectAll :: Connection -> [HostName] -> Network.PortID -> IO Connection
|
-- | Establish connections to a list of MongoDB servers specifying each port.
|
||||||
connectAll c [] _ = return c
|
connectClusterOnPort :: [(HostName, Network.PortID)] -> IO Connection
|
||||||
connectAll c (host:xs) port = do
|
connectClusterOnPort [] = throwOpFailure "No hostnames in list"
|
||||||
|
connectClusterOnPort xs = newConnection >>= flip connectAll xs
|
||||||
|
|
||||||
|
connectAll :: Connection -> [(HostName, Network.PortID)] -> IO Connection
|
||||||
|
connectAll c [] = return c
|
||||||
|
connectAll c ((host, port) : xs) = do
|
||||||
h <- Network.connectTo host port
|
h <- Network.connectTo host port
|
||||||
hSetBuffering h NoBuffering
|
hSetBuffering h NoBuffering
|
||||||
connectAll (c {cHandles = h:(cHandles c)}) xs port
|
connectAll (c {cHandles = h:(cHandles c)}) xs
|
||||||
|
|
||||||
-- | Establish a connection to a MongoDB server on a non-standard port
|
-- | Establish a connection to a MongoDB server on a non-standard port
|
||||||
connectOnPort :: HostName -> Network.PortID -> IO Connection
|
connectOnPort :: HostName -> Network.PortID -> IO Connection
|
||||||
connectOnPort host port = do
|
connectOnPort host port = do
|
||||||
c <- newConnection
|
c <- newConnection
|
||||||
connectAll c [host] port
|
connectAll c [(host, port)]
|
||||||
|
|
||||||
newConnection :: IO Connection
|
newConnection :: IO Connection
|
||||||
newConnection = do
|
newConnection = do
|
||||||
|
|
Loading…
Reference in a new issue