From 121dcbfd9352f6d25b3a843bf381de27c817fdcc Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Mon, 18 Jan 2010 17:31:41 -0600 Subject: [PATCH] findOne --- Database/MongoDB.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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'.