Throw exception when insertAll encounters big doc
- insertAll should throw an exception if it encounters a document too big for one message. However all other documents will be inserted. - slightly edit docs
This commit is contained in:
parent
bedaa744ba
commit
80ebc6f756
2 changed files with 11 additions and 4 deletions
|
@ -433,7 +433,11 @@ insert_ :: (MonadIO m) => Collection -> Document -> Action m ()
|
||||||
insert_ col doc = insert col doc >> return ()
|
insert_ col doc = insert col doc >> return ()
|
||||||
|
|
||||||
insertMany :: (MonadIO m) => Collection -> [Document] -> Action m [Value]
|
insertMany :: (MonadIO m) => Collection -> [Document] -> Action m [Value]
|
||||||
-- ^ Insert documents into collection and return their \"_id\" values, which are created automatically if not supplied. If a document fails to be inserted (eg. due to duplicate key) then remaining docs are aborted, and LastError is set.
|
-- ^ Insert documents into collection and return their \"_id\" values,
|
||||||
|
-- which are created automatically if not supplied.
|
||||||
|
-- If a document fails to be inserted (eg. due to duplicate key)
|
||||||
|
-- then remaining docs are aborted, and LastError is set.
|
||||||
|
-- An exception will be throw if any error occurs.
|
||||||
insertMany = insert' []
|
insertMany = insert' []
|
||||||
|
|
||||||
insertMany_ :: (MonadIO m) => Collection -> [Document] -> Action m ()
|
insertMany_ :: (MonadIO m) => Collection -> [Document] -> Action m ()
|
||||||
|
@ -441,7 +445,10 @@ insertMany_ :: (MonadIO m) => Collection -> [Document] -> Action m ()
|
||||||
insertMany_ col docs = insertMany col docs >> return ()
|
insertMany_ col docs = insertMany col docs >> return ()
|
||||||
|
|
||||||
insertAll :: (MonadIO m) => Collection -> [Document] -> Action m [Value]
|
insertAll :: (MonadIO m) => Collection -> [Document] -> Action m [Value]
|
||||||
-- ^ Insert documents into collection and return their \"_id\" values, which are created automatically if not supplied. If a document fails to be inserted (eg. due to duplicate key) then remaining docs are still inserted. LastError is set if any doc fails, not just last one.
|
-- ^ Insert documents into collection and return their \"_id\" values,
|
||||||
|
-- which are created automatically if not supplied. If a document fails
|
||||||
|
-- to be inserted (eg. due to duplicate key) then remaining docs
|
||||||
|
-- are still inserted.
|
||||||
insertAll = insert' [KeepGoing]
|
insertAll = insert' [KeepGoing]
|
||||||
|
|
||||||
insertAll_ :: (MonadIO m) => Collection -> [Document] -> Action m ()
|
insertAll_ :: (MonadIO m) => Collection -> [Document] -> Action m ()
|
||||||
|
@ -493,7 +500,7 @@ insert' opts col docs = do
|
||||||
chunkResults <- interruptibleFor ordered (zip lSums chunks) $ insertBlock opts col
|
chunkResults <- interruptibleFor ordered (zip lSums chunks) $ insertBlock opts col
|
||||||
|
|
||||||
let lchunks = lefts preChunks
|
let lchunks = lefts preChunks
|
||||||
when ((not $ null lchunks) && ordered) $ do
|
when (not $ null lchunks) $ do
|
||||||
liftIO $ throwIO $ head lchunks
|
liftIO $ throwIO $ head lchunks
|
||||||
|
|
||||||
let lresults = lefts chunkResults
|
let lresults = lefts chunkResults
|
||||||
|
|
|
@ -171,7 +171,7 @@ spec = around withCleanDatabase $ do
|
||||||
|
|
||||||
liftIO $ (length returnedDocs) `shouldBe` 1000
|
liftIO $ (length returnedDocs) `shouldBe` 1000
|
||||||
it "skips one too big document" $ do
|
it "skips one too big document" $ do
|
||||||
db $ insertAll_ "hugeDocCollection" [hugeDocument]
|
(db $ insertAll_ "hugeDocCollection" [hugeDocument]) `shouldThrow` anyException
|
||||||
db $ do
|
db $ do
|
||||||
cur <- find $ (select [] "hugeDocCollection") {limit = 100000, batchSize = 100000}
|
cur <- find $ (select [] "hugeDocCollection") {limit = 100000, batchSize = 100000}
|
||||||
returnedDocs <- rest cur
|
returnedDocs <- rest cur
|
||||||
|
|
Loading…
Reference in a new issue