diff --git a/Database/MongoDB.hs b/Database/MongoDB.hs index 51721dd..f900783 100644 --- a/Database/MongoDB.hs +++ b/Database/MongoDB.hs @@ -36,9 +36,9 @@ module Database.MongoDB QueryOpt(..), UpdateFlag(..), delete, insert, insertMany, query, remove, update, - -- * Convience database operations - find, quickFind, quickFind', - -- * Cursor operations + -- * Convience collection operations + find, findOne, quickFind, quickFind', + -- * Cursor Cursor, allDocs, allDocs', finish, nextDoc, ) @@ -259,6 +259,14 @@ insertMany c col docs = do find :: Connection -> Collection -> Selector -> IO Cursor find c col sel = query c col [] 0 0 sel [] +-- | Query, but only return the first result, if any. +findOne :: Connection -> Collection -> Selector -> IO (Maybe BsonDoc) +findOne c col sel = do + cur <- find c col sel + el <- nextDoc cur + finish cur + return el + -- | 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'.