- data Connection
- connect :: HostName -> IO Connection
- connectOnPort :: HostName -> PortID -> IO Connection
- conClose :: Connection -> IO ()
- disconnect :: Connection -> IO ()
- dropDatabase :: Connection -> Database -> IO ()
- type Database = String
- data MongoDBCollectionInvalid
- data ColCreateOpt
- collectionNames :: Connection -> Database -> IO [Collection]
- createCollection :: Connection -> Collection -> [ColCreateOpt] -> IO ()
- dropCollection :: Connection -> Collection -> IO ()
- validateCollection :: Connection -> Collection -> IO String
- type Collection = String
- type FieldSelector = [ByteString]
- type NumToSkip = Int32
- type NumToReturn = Int32
- type Selector = BsonDoc
- data QueryOpt
- data UpdateFlag
- count :: Connection -> Collection -> IO Int64
- countMatching :: Connection -> Collection -> Selector -> IO Int64
- delete :: Connection -> Collection -> Selector -> IO RequestID
- insert :: Connection -> Collection -> BsonDoc -> IO RequestID
- insertMany :: Connection -> Collection -> [BsonDoc] -> IO RequestID
- query :: Connection -> Collection -> [QueryOpt] -> NumToSkip -> NumToReturn -> Selector -> FieldSelector -> IO Cursor
- remove :: Connection -> Collection -> Selector -> IO RequestID
- update :: Connection -> Collection -> [UpdateFlag] -> Selector -> BsonDoc -> IO RequestID
- find :: Connection -> Collection -> Selector -> IO Cursor
- findOne :: Connection -> Collection -> Selector -> IO (Maybe BsonDoc)
- quickFind :: Connection -> Collection -> Selector -> IO [BsonDoc]
- quickFind' :: Connection -> Collection -> Selector -> IO [BsonDoc]
- data Cursor
- allDocs :: Cursor -> IO [BsonDoc]
- allDocs' :: Cursor -> IO [BsonDoc]
- finish :: Cursor -> IO ()
- nextDoc :: Cursor -> IO (Maybe BsonDoc)
Connection
data Connection Source
A handle to a database connection
connect :: HostName -> IO ConnectionSource
Estabilish a connection to a MongoDB server
connectOnPort :: HostName -> PortID -> IO ConnectionSource
Estabilish a connection to a MongoDB server on a non-standard port
conClose :: Connection -> IO ()Source
Close database connection
disconnect :: Connection -> IO ()Source
Alias for conClose
dropDatabase :: Connection -> Database -> IO ()Source
Drop a database.
Database
data ColCreateOpt Source
collectionNames :: Connection -> Database -> IO [Collection]Source
Return a list of collections in Database.
createCollection :: Connection -> Collection -> [ColCreateOpt] -> IO ()Source
Create a new collection in this database.
Normally collection creation is automatic. This function should
only be needed if you want to specify ColCreateOpt
s on creation.
MongoDBCollectionInvalid
is thrown if the collection already
exists.
dropCollection :: Connection -> Collection -> IO ()Source
Drop a collection.
validateCollection :: Connection -> Collection -> IO StringSource
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
Collection
type Collection = StringSource
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 FieldSelector = [ByteString]Source
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.
Sets the number of documents to omit - starting from the first document in the resulting dataset - when returning the result of the query.
type NumToReturn = Int32Source
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.
A BsonDoc
representing restrictions for a query much like the
where part of an SQL query.
Options that control the behavior of a query
operation.
data UpdateFlag Source
Options that effect the behavior of a update
operation.
count :: Connection -> Collection -> IO Int64Source
Return the number of documents in Collection.
countMatching :: Connection -> Collection -> Selector -> IO Int64Source
Return the number of documents in Collection matching Selector
delete :: Connection -> Collection -> Selector -> IO RequestIDSource
Delete documents matching Selector from the given Collection.
insert :: Connection -> Collection -> BsonDoc -> IO RequestIDSource
Insert a single document into Collection.
insertMany :: Connection -> Collection -> [BsonDoc] -> IO RequestIDSource
Insert a list of documents into Collection.
query :: Connection -> Collection -> [QueryOpt] -> NumToSkip -> NumToReturn -> Selector -> FieldSelector -> IO CursorSource
Open a cursor to find documents in Collection that match Selector. See the documentation for each argument's type for information about how it effects the query.
remove :: Connection -> Collection -> Selector -> IO RequestIDSource
An alias for delete
.
update :: Connection -> Collection -> [UpdateFlag] -> Selector -> BsonDoc -> IO RequestIDSource
Update documents with BsonDoc in Collection that match Selector.
Convience collection operations
find :: Connection -> Collection -> Selector -> IO CursorSource
Open a cursor to find documents. If you need full functionality,
see query
findOne :: Connection -> Collection -> Selector -> IO (Maybe BsonDoc)Source
Query, but only return the first result, if any.
quickFind :: Connection -> Collection -> Selector -> IO [BsonDoc]Source
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 -> Collection -> Selector -> IO [BsonDoc]Source
Perform a query and return the result as a strict list.
Cursor
allDocs :: Cursor -> IO [BsonDoc]Source
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]Source
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.