-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A driver for MongoDB -- -- This driver lets you connect to MongoDB, do inserts, queries, updates, -- etc. Also has many convience functions inspired by HDBC such as more -- easily converting between the BsonValue types and native Haskell -- types. @package mongoDB @version 0.3 module Database.MongoDB.BSON -- | BsonValue is the type that can be used as a key in a BsonDoc. data BsonValue BsonDouble :: Double -> BsonValue BsonString :: ByteString -> BsonValue BsonObject :: BsonDoc -> BsonValue BsonArray :: [BsonValue] -> BsonValue BsonUndefined :: BsonValue BsonBinary :: BinarySubType -> ByteString -> BsonValue BsonObjectId :: ByteString -> BsonValue BsonBool :: !Bool -> BsonValue BsonDate :: POSIXTime -> BsonValue BsonNull :: BsonValue BsonRegex :: ByteString -> String -> BsonValue BsonSymbol :: ByteString -> BsonValue BsonInt32 :: Int32 -> BsonValue BsonInt64 :: Int64 -> BsonValue BsonCodeWScope :: ByteString -> BsonDoc -> BsonValue BsonMinKey :: BsonValue BsonMaxKey :: BsonValue -- | BSON Document: this is the top-level (but recursive) type that all -- MongoDB collections work in terms of. It is a mapping between strings -- (Data.ByteString.Lazu.UTF8.ByteString) and BsonValues. -- It can be constructed either from a Map (eg -- BsonDoc myMap) or from a associative list (eg -- toBsonDoc myAL). type BsonDoc = Map ByteString BsonValue data BinarySubType BSTUNDEFINED1 :: BinarySubType BSTFunction :: BinarySubType BSTByteArray :: BinarySubType BSTUUID :: BinarySubType BSTUNDEFINED2 :: BinarySubType BSTMD5 :: BinarySubType BSTUserDefined :: BinarySubType -- | An empty BsonDoc empty :: BsonDoc -- | Return the BsonValue for given key, if any. lookup :: (BsonDocOps a) => a -> BsonDoc -> Maybe BsonValue -- | Convert a BsonValue into a native Haskell type. fromBson :: (BsonConv a b, Convertible a b) => a -> b -- | Convert a native Haskell type into a BsonValue. toBson :: (BsonConv a b, Convertible b a) => b -> a -- | Unwrap BsonDoc to be a Map fromBsonDoc :: (BsonDocOps a) => BsonDoc -> [(a, BsonValue)] -- | Construct a BsonDoc from an associative list toBsonDoc :: (BsonDocOps a) => [(a, BsonValue)] -> BsonDoc getBsonDoc :: Get BsonDoc putBsonDoc :: BsonDoc -> Put instance Show BinarySubType instance Read BinarySubType instance Enum BinarySubType instance Eq BinarySubType instance Ord BinarySubType instance Show DataType instance Read DataType instance Enum DataType instance Eq DataType instance Ord DataType instance Show BsonValue instance Eq BsonValue instance Ord BsonValue instance (Convertible BsonValue a) => Convertible (Maybe BsonValue) (Maybe a) instance Convertible BsonValue Int64 instance Convertible BsonValue Int32 instance Convertible BsonValue Integer instance Convertible BsonValue Int instance Convertible BsonValue POSIXTime instance Convertible BsonValue Bool instance Convertible BsonValue [Int64] instance Convertible BsonValue [Int32] instance Convertible BsonValue [POSIXTime] instance Convertible BsonValue [Bool] instance Convertible BsonValue [String] instance Convertible BsonValue [Float] instance Convertible BsonValue [Double] instance Convertible BsonValue [(ByteString, BsonValue)] instance Convertible BsonValue [(String, BsonValue)] instance Convertible BsonValue (Map String BsonValue) instance Convertible BsonValue BsonDoc instance Convertible BsonValue ByteString instance Convertible BsonValue ByteString instance Convertible BsonValue String instance Convertible BsonValue Float instance Convertible BsonValue Double instance (Convertible a BsonValue) => Convertible (Maybe a) BsonValue instance Convertible Int64 BsonValue instance Convertible Int32 BsonValue instance Convertible Integer BsonValue instance Convertible Int BsonValue instance Convertible Bool BsonValue instance Convertible POSIXTime BsonValue instance Convertible [Int64] BsonValue instance Convertible [Int32] BsonValue instance Convertible [Integer] BsonValue instance Convertible [Int] BsonValue instance Convertible [POSIXTime] BsonValue instance Convertible [Bool] BsonValue instance Convertible [(String, BsonValue)] BsonValue instance Convertible [(ByteString, BsonValue)] BsonValue instance Convertible (Map String BsonValue) BsonValue instance Convertible BsonDoc BsonValue instance Convertible [ByteString] BsonValue instance Convertible [ByteString] BsonValue instance Convertible [String] BsonValue instance Convertible [Float] BsonValue instance Convertible [Double] BsonValue instance Convertible ByteString BsonValue instance Convertible ByteString BsonValue instance Convertible String BsonValue instance Convertible Float BsonValue instance Convertible Double BsonValue instance BsonConv (Maybe BsonValue) (Maybe a) instance BsonConv BsonValue a instance BsonDocOps String instance BsonDocOps ByteString instance Typeable BsonValue module Database.MongoDB -- | A list of handles to database connections data Connection data ConnectOpt -- | It's fine to connect to the slave SlaveOK :: ConnectOpt -- | Establish a connection to a MongoDB server connect :: HostName -> [ConnectOpt] -> IO Connection -- | Establish a connection to a MongoDB server on a non-standard port connectOnPort :: HostName -> PortID -> [ConnectOpt] -> IO Connection -- | Close database connection conClose :: Connection -> IO () -- | Alias for conClose disconnect :: Connection -> IO () -- | Drop a database. dropDatabase :: Connection -> Database -> IO () -- | Establish connections to a list of MongoDB servers connectCluster :: [HostName] -> [ConnectOpt] -> IO Connection -- | Establish connections to a list of MongoDB servers specifying each -- port. connectClusterOnPort :: [(HostName, PortID)] -> [ConnectOpt] -> IO Connection -- | Get information about the MongoDB server we're connected to. serverInfo :: Connection -> IO BsonDoc -- | Shut down the MongoDB server. -- -- Force a clean exit, flushing and closing all data files. Note that it -- will wait until all ongoing operations are complete. serverShutdown :: Connection -> IO BsonDoc -- | Information about the databases on the server. databasesInfo :: Connection -> IO BsonDoc -- | Return a list of database names on the server. databaseNames :: Connection -> IO [Database] -- | The name of a database. type Database = ByteString data MongoDBCollectionInvalid type Password = String type Username = String data ColCreateOpt -- | Desired initial size for the collection (in bytes). must be less than -- or equal to 10000000000. For capped collections this size is the max -- size of the collection. CCOSize :: Int64 -> ColCreateOpt -- | If True, this is a capped collection. CCOCapped :: Bool -> ColCreateOpt -- | Maximum number of objects if capped. CCOMax :: Int64 -> ColCreateOpt -- | Return a list of collections in Database. collectionNames :: Connection -> Database -> IO [FullCollection] -- | Create a new collection in this database. -- -- Normally collection creation is automatic. This function should only -- be needed if you want to specify ColCreateOpts on creation. -- MongoDBCollectionInvalid is thrown if the collection already -- exists. createCollection :: Connection -> FullCollection -> [ColCreateOpt] -> IO () -- | Drop a collection. dropCollection :: Connection -> FullCollection -> IO () -- | Rename a collection--first FullCollection argument is the -- existing name, the second is the new name. At the moment this command -- can also be used to move a collection between databases. renameCollection :: Connection -> FullCollection -> FullCollection -> IO () -- | Run a database command. Usually this is unneeded as driver wraps all -- of the commands for you (eg createCollection, -- dropCollection, etc). runCommand :: Connection -> Database -> BsonDoc -> IO BsonDoc -- | Return a string of validation info about the collection. -- -- Example output (note this probably can/will change with different -- versions of the server): -- --
-- validate -- details: 0x7fe5cc2c1da4 ofs:e7da4 -- firstExtent:0:24100 ns:test.foo.bar -- lastExtent:0:24100 ns:test.foo.bar -- # extents:1 -- datasize?:180 nrecords?:5 lastExtentSize:1024 -- padding:1 -- first extent: -- loc:0:24100 xnext:null xprev:null -- nsdiag:test.foo.bar -- size:1024 firstRecord:0:241e4 lastRecord:0:24280 -- 5 objects found, nobj:5 -- 260 bytes data w/headers -- 180 bytes data wout/headers -- deletedList: 0100100000000000000 -- deleted: n: 4 size: 588 -- nIndexes:1 -- test.foo.bar.$_id_ keys:5 --validateCollection :: Connection -> FullCollection -> IO String auth :: Connection -> Database -> Username -> Password -> IO BsonDoc -- | create a new user in the current Database addUser :: Connection -> Database -> Username -> Password -> IO BsonDoc -- | log into the mongodb Database attached to the Connection login :: Connection -> Database -> Username -> Password -> IO BsonDoc logout :: Connection -> Database -> IO () -- | The same as FullCollection but without the Database -- prefix. type Collection = ByteString -- | A list of field names that limits the fields in the returned -- documents. The list can contains zero or more elements, each of which -- is the name of a field that should be returned. An empty list means -- that no limiting is done and all fields are returned. type FieldSelector = [ByteString] -- | The full collection name. The full collection name is the -- concatenation of the database name with the collection name, using a -- . for the concatenation. For example, for the database -- foo and the collection bar, the full collection name -- is foo.bar. type FullCollection = ByteString -- | Sets the number of documents to omit - starting from the first -- document in the resulting dataset - when returning the result of the -- query. type NumToSkip = Int32 -- | This controls how many documents are returned at a time. The cursor -- works by requesting NumToReturn documents, which are then -- immediately all transfered over the network; these are held locally -- until the those NumToReturn are all consumed and then the -- network will be hit again for the next NumToReturn documents. -- -- If the value 0 is given, the database will choose the number -- of documents to return. -- -- Otherwise choosing a good value is very dependant on the document size -- and the way the cursor is being used. type NumToReturn = Int32 -- | A BsonDoc representing restrictions for a query much like the -- where part of an SQL query. type Selector = BsonDoc -- | Options that control the behavior of a query operation. data QueryOpt QOTailableCursor :: QueryOpt QOSlaveOK :: QueryOpt QOOpLogReplay :: QueryOpt QONoCursorTimeout :: QueryOpt -- | Options that effect the behavior of a update operation. data UpdateFlag UFUpsert :: UpdateFlag UFMultiupdate :: UpdateFlag -- | Return the number of documents in FullCollection. count :: Connection -> FullCollection -> IO Int64 -- | Return the number of documents in FullCollection matching -- Selector countMatching :: Connection -> FullCollection -> Selector -> IO Int64 -- | Delete documents matching Selector from the given -- FullCollection. delete :: Connection -> FullCollection -> Selector -> IO RequestID -- | Insert a single document into FullCollection. insert :: Connection -> FullCollection -> BsonDoc -> IO RequestID -- | Insert a list of documents into FullCollection. insertMany :: Connection -> FullCollection -> [BsonDoc] -> IO RequestID -- | Open a cursor to find documents in FullCollection that match -- Selector. See the documentation for each argument's type for -- information about how it effects the query. query :: Connection -> FullCollection -> [QueryOpt] -> NumToSkip -> NumToReturn -> Selector -> FieldSelector -> IO Cursor -- | An alias for delete. remove :: Connection -> FullCollection -> Selector -> IO RequestID -- | Update documents with BsonDoc in FullCollection that -- match Selector. update :: Connection -> FullCollection -> [UpdateFlag] -> Selector -> BsonDoc -> IO RequestID -- | Conveniently stores the BsonDoc to the FullCollection if -- there is an _id present in the BsonDoc then it already has a -- place in the DB, so we update it using the _id, otherwise we insert it save :: Connection -> FullCollection -> BsonDoc -> IO RequestID -- | Open a cursor to find documents. If you need full functionality, see -- query find :: Connection -> FullCollection -> Selector -> IO Cursor -- | Query, but only return the first result, if any. findOne :: Connection -> FullCollection -> Selector -> IO (Maybe BsonDoc) -- | Perform a query and return the result as a lazy list. Be sure to -- understand the comments about using the lazy list given for -- allDocs. quickFind :: Connection -> FullCollection -> Selector -> IO [BsonDoc] -- | Perform a query and return the result as a strict list. quickFind' :: Connection -> FullCollection -> Selector -> IO [BsonDoc] -- | Use this in the place of the query portion of a select type query This -- uses javascript and a scope supplied by a BsonDoc to evaluate -- documents in the database for retrieval. -- -- Example: -- --
-- findOne conn mycoll $ whereClause "this.name == (name1 + name2)"
-- (toBsonDoc [("name1", toBson "mar"), ("name2", toBson "tha")])
--
whereClause :: String -> BsonDoc -> BsonDoc
-- | An Iterator over the results of a query. Use nextDoc to get
-- each successive result document, or allDocs or allDocs'
-- to get lazy or strict lists of results.
data Cursor
-- | Return a lazy list of all (of the rest) of the documents in the
-- cursor. This works much like hGetContents--it will lazily read the
-- cursor data out of the database as the list is used. The cursor is
-- automatically closed when the list has been fully read.
--
-- If you manually finish the cursor before consuming off this list you
-- won't get all the original documents in the cursor.
--
-- If you don't consume to the end of the list, you must manually close
-- the cursor or you will leak the cursor, which may also leak on the
-- database side.
allDocs :: Cursor -> IO [BsonDoc]
-- | Returns a strict list of all (of the rest) of the documents in the
-- cursor. This means that all of the documents will immediately be read
-- out of the database and loaded into memory.
allDocs' :: Cursor -> IO [BsonDoc]
-- | Manually close a cursor -- usually not needed if you use
-- allDocs, allDocs', or nextDoc.
finish :: Cursor -> IO ()
-- | Return one document or Nothing if there are no more. Automatically
-- closes the cursor when last document is read
nextDoc :: Cursor -> IO (Maybe BsonDoc)
-- | The field key to index on.
type Key = ByteString
-- | Should this index guarantee uniqueness?
type Unique = Bool
-- | Direction to index.
data Direction
Ascending :: Direction
Descending :: Direction
-- | Create a new index on FullCollection on the list of Key
-- / Direction pairs.
createIndex :: Connection -> FullCollection -> [(Key, Direction)] -> Unique -> IO ByteString
-- | Drop the specified index on the given FullCollection.
dropIndex :: Connection -> FullCollection -> [(Key, Direction)] -> IO ()
-- | Drop all indexes on FullCollection.
dropIndexes :: Connection -> FullCollection -> IO ()
-- | Return a BsonDoc describing the existing indexes on
-- FullCollection.
--
-- With the current server versions (1.2) this will return documents such
-- as:
--
--
-- {"key": {"lastname": -1, "firstname": 1},
-- "name": "lastname_-1_firstname_1",
-- "ns": "mydb.people",
-- "unique": true}
--
--
-- Which is a single key that indexes on lastname (descending)
-- and then firstname (ascending) on the collection
-- people of the database mydb with a uniqueness
-- requirement.
indexInformation :: Connection -> FullCollection -> IO [BsonDoc]
instance Show Direction
instance Eq Direction
instance Show Reply
instance Show Hdr
instance Show UpdateFlag
instance Enum UpdateFlag
instance Show QueryOpt
instance Eq MongoDBConnectionFailure
instance Show MongoDBConnectionFailure
instance Read MongoDBConnectionFailure
instance Eq MongoDBOperationFailure
instance Show MongoDBOperationFailure
instance Read MongoDBOperationFailure
instance Eq MongoDBCollectionInvalid
instance Show MongoDBCollectionInvalid
instance Read MongoDBCollectionInvalid
instance Eq MongoDBInternalError
instance Show MongoDBInternalError
instance Read MongoDBInternalError
instance Show Opcode
instance Eq Opcode
instance Show ColCreateOpt
instance Eq ColCreateOpt
instance Show ConnectOpt
instance Eq ConnectOpt
instance Exception MongoDBConnectionFailure
instance Typeable MongoDBConnectionFailure
instance Exception MongoDBOperationFailure
instance Typeable MongoDBOperationFailure
instance Exception MongoDBCollectionInvalid
instance Typeable MongoDBCollectionInvalid
instance Exception MongoDBInternalError
instance Typeable MongoDBInternalError