From 344c6bb97587a02d8a121842f1615298b36e1dd1 Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Sat, 16 Jan 2010 18:54:26 -0600 Subject: [PATCH] add find command: simpler to use then query for most uses --- Database/MongoDB.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Database/MongoDB.hs b/Database/MongoDB.hs index 095173e..4339d44 100644 --- a/Database/MongoDB.hs +++ b/Database/MongoDB.hs @@ -3,6 +3,7 @@ module Database.MongoDB connect, connectOnPort, conClose, delete, insert, insertMany, query, remove, update, nextDoc, finish, + find, Collection, FieldSelector, NumToSkip, NumToReturn, RequestID, Selector, Opcode(..), QueryOpt(..), @@ -15,7 +16,7 @@ import Data.Binary import Data.Binary.Get import Data.Binary.Put import Data.Bits -import Data.ByteString.Char8 +import Data.ByteString.Char8 hiding (find) import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.UTF8 as L8 import Data.Int @@ -147,6 +148,11 @@ insertMany c col docs = do L.hPut (cHandle c) msg return reqID +{- | Open a cursor to find documents. If you need full functionality, +see 'query' -} +find :: Connection -> Collection -> Selector -> IO Cursor +find c col sel = query c col [] 0 0 sel Nothing + query :: Connection -> Collection -> [QueryOpt] -> NumToSkip -> NumToReturn -> Selector -> Maybe FieldSelector -> IO Cursor query c col opts skip ret sel fsel = do @@ -228,6 +234,8 @@ getReply h = do return $ (Reply respFlags cursorID startFrom numReturned) +{- | Return one document or Nothing if there are no more. +Automatically closes the curosr when last document is read -} nextDoc :: Cursor -> IO (Maybe BSONObject) nextDoc cur = do closed <- readIORef $ curClosed cur