From 183e6193629cab8578ab920d4670cc33f4050c10 Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Sat, 16 Jan 2010 19:38:11 -0600 Subject: [PATCH] allDocs': a strict version of allDocs --- Database/MongoDB.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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