mongoDB-0.6.1: A driver for MongoDB

Database.MongoDB.Connection

Contents

Description

A replica set is a set of servers that mirror each other (a non-replicated server can act like a replica set of one). One server in a replica set is the master and the rest are slaves. When the master goes down, one of the slaves becomes master. The ReplicaSet object in this client maintains a list of servers that it currently knows are in the set. It refreshes this list every time it establishes a new connection with one of the servers in the set. Each server in the set knows who the other member in the set are, and who is master. The user asks the ReplicaSet object for a new master or slave connection. When a connection fails, the user must ask the ReplicaSet for a new connection (which most likely will connect to another server since the previous one failed). When connecting to a new server you loose all session state that was stored with the old server, which includes open cursors and temporary map-reduce output collections. Attempting to read from a lost cursor on a new server will raise a ServerFailure exception. Attempting to read a lost map-reduce temp output on a new server will return an empty set (not an error, like it maybe should).

Synopsis

Server

data Server Source

Constructors

Server HostName PortID 

Instances

server :: HostName -> ServerSource

Server on default MongoDB port

showHostPort :: Server -> StringSource

Display server as "host:port"

readHostPort :: String -> ServerSource

Read string "host:port" as 'Server host port' or "host" as 'server host' (default port). Error if string does not match either syntax.

readHostPortF :: Monad m => String -> m ServerSource

Read string "host:port" as 'Server host port' or "host" as 'server host' (default port). Fail if string does not match either syntax.

ReplicaSet

data ReplicaSet Source

Reference to a replica set of servers. Ok if really not a replica set and just a stand-alone server, in which case it acts like a replica set of one.

replicaSet :: [Server] -> IO ReplicaSetSource

Create a reference to a replica set with servers as the initial seed list (a subset of the servers in the replica set)

replicaServers :: ReplicaSet -> IO [Server]Source

Return current list of known servers in replica set. This list is updated on every newConnection.

data MasterOrSlave Source

Constructors

Master

connect to master only

SlaveOk

connect to a slave, or master if no slave available

type FailedToConnect = [(Server, IOError)]Source

All servers tried in replica set along with reason why each failed to connect

newConnection :: MasterOrSlave -> ReplicaSet -> IO (Either FailedToConnect Connection)Source

Create a connection to a master or slave in the replica set. Don't forget to close connection when you are done using it even if Failure exception is raised when using it. newConnection returns Left if failed to connect to any server in replica set. TODO: prefer slave over master when SlaveOk and both are available.

Connection

type Connection = Pipe Handle ByteStringSource

Thread-safe TCP connection to server with pipelined requests

connect :: Server -> IO (Either IOError Connection)Source

Create a connection to the given server (as opposed to connecting to some server in a replica set via newConnection). Return Left IOError if failed to connect.

Resource

class Resource m r whereSource

Methods

close :: r -> m ()Source

isClosed :: r -> m BoolSource

Instances