diff --git a/Database/MongoDB/Query.hs b/Database/MongoDB/Query.hs index 1f5dfc2..5c775a2 100644 --- a/Database/MongoDB/Query.hs +++ b/Database/MongoDB/Query.hs @@ -670,7 +670,6 @@ updateBlock ordered col (prevCount, docs) = do NoConfirm -> ["w" =: (0 :: Int)] Confirm params -> params doc <- runCommand $ updateCommandDocument col ordered docs writeConcern - let writeConcernError = maybeToList $ do wceDoc <- doc !? "writeConcernError" return $ docToWriteConcernError wceDoc @@ -678,7 +677,7 @@ updateBlock ordered col (prevCount, docs) = do let writeErrors = map docToWriteError $ fromMaybe [] (doc !? "writeErrors") let upsertedDocs = fromMaybe [] (doc !? "upserted") return $ UpdateResult - False -- TODO it should be changed accordingly + ((not $ true1 "ok" doc) || (length writeErrors > 0)) (at "n" doc) (at "nModified" doc) (map docToUpserted upsertedDocs) diff --git a/test/QuerySpec.hs b/test/QuerySpec.hs index bf274ec..728fd01 100644 --- a/test/QuerySpec.hs +++ b/test/QuerySpec.hs @@ -250,15 +250,16 @@ spec = around withCleanDatabase $ do it "can process different updates" $ do _ <- db $ insert "team" ["name" =: "Yankees", "league" =: "American", "score" =: (Nothing :: Maybe Int)] _ <- db $ insert "team" ["name" =: "Giants" , "league" =: "MiLB", "score" =: (1 :: Int)] - (db $ updateMany "team" [ ( ["name" =: "Yankees"] - , ["$inc" =: ["score" =: (1 :: Int)]] - , [] - ) - , ( ["name" =: "Giants"] - , ["$inc" =: ["score" =: (2 :: Int)]] - , [] - ) - ]) `shouldThrow` anyException + updateResult <- (db $ updateMany "team" [ ( ["name" =: "Yankees"] + , ["$inc" =: ["score" =: (1 :: Int)]] + , [] + ) + , ( ["name" =: "Giants"] + , ["$inc" =: ["score" =: (2 :: Int)]] + , [] + ) + ]) + failed updateResult `shouldBe` True updatedResult <- db $ rest =<< find ((select [] "team") {project = ["_id" =: (0 :: Int)]}) (L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)] , ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (1 :: Int)] @@ -280,15 +281,16 @@ spec = around withCleanDatabase $ do it "can process different updates" $ do _ <- db $ insert "team" ["name" =: "Yankees", "league" =: "American", "score" =: (Nothing :: Maybe Int)] _ <- db $ insert "team" ["name" =: "Giants" , "league" =: "MiLB", "score" =: (1 :: Int)] - (db $ updateAll "team" [ ( ["name" =: "Yankees"] - , ["$inc" =: ["score" =: (1 :: Int)]] - , [] - ) - , ( ["name" =: "Giants"] - , ["$inc" =: ["score" =: (2 :: Int)]] - , [] - ) - ]) `shouldThrow` anyException + updateResult <- (db $ updateAll "team" [ ( ["name" =: "Yankees"] + , ["$inc" =: ["score" =: (1 :: Int)]] + , [] + ) + , ( ["name" =: "Giants"] + , ["$inc" =: ["score" =: (2 :: Int)]] + , [] + ) + ]) + failed updateResult `shouldBe` True updatedResult <- db $ rest =<< find ((select [] "team") {project = ["_id" =: (0 :: Int)]}) (L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)] , ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (3 :: Int)]