diff --git a/Database/MongoDB.hs b/Database/MongoDB.hs index 95d5132..33a38e3 100644 --- a/Database/MongoDB.hs +++ b/Database/MongoDB.hs @@ -28,7 +28,7 @@ module Database.MongoDB connect, connectOnPort, conClose, delete, insert, insertMany, query, remove, update, find, - allDocs, finish, nextDoc, + allDocs, allDocs', finish, nextDoc, Collection, FieldSelector, NumToSkip, NumToReturn, RequestID, Selector, Opcode(..), QueryOpt(..), @@ -298,6 +298,16 @@ allDocs cur = unsafeInterleaveIO $ do Nothing -> return [] Just d -> allDocs cur >>= return . (d :) +{- | 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 [BSONObject] +allDocs' cur = do + doc <- nextDoc cur + case doc of + Nothing -> return [] + Just d -> allDocs' cur >>= return . (d :) + getFirstDoc docBytes = flip runGet docBytes $ do doc <- get docBytes' <- getRemainingLazyByteString