From 52547937679e500d4c0e93ed2e6f2cea4aae5997 Mon Sep 17 00:00:00 2001 From: Victor Denisov Date: Mon, 22 Aug 2016 21:36:10 -0700 Subject: [PATCH] Throw exceptions in case of single document updates --- Database/MongoDB/Query.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index e8c316d..77a4049 100644 --- a/Database/MongoDB/Query.hs +++ b/Database/MongoDB/Query.hs @@ -574,8 +574,10 @@ update :: (MonadIO m) => [UpdateOption] -> Selection -> Document -> Action m () -- ^ Update first document in selection using updater document, unless 'MultiUpdate' option is supplied then update all documents in selection. If 'Upsert' option is supplied then treat updater as document and insert it if selection is empty. update opts (Select sel col) up = do - _ <- update' True col [(sel, up, opts)] - return () + res <- update' True col [(sel, up, opts)] + if not $ null $ writeErrors res + then liftIO $ throwIO $ WriteFailure 0 (show $ head $ writeErrors res) + else return () updateCommandDocument :: Collection -> Bool -> [Document] -> Document -> Document updateCommandDocument col ordered updates writeConcern =