Add test and fix for updateMany nMatched and nModified

This commit is contained in:
Victor Denisov 2017-05-29 12:58:39 -07:00
parent 50b7fef240
commit a1e19379f6
2 changed files with 20 additions and 12 deletions

View file

@ -744,13 +744,13 @@ updateBlock ordered col (prevCount, docs) = do
let n = fromMaybe 0 $ doc !? "n"
let writeErrorsResults =
case look "writeErrors" doc of
Nothing -> WriteResult False 0 Nothing n [] [] []
Just (Array err) -> WriteResult True 0 Nothing n [] (map (anyToWriteError prevCount) err) []
Nothing -> WriteResult False 0 (Just 0) 0 [] [] []
Just (Array err) -> WriteResult True 0 (Just 0) 0 [] (map (anyToWriteError prevCount) err) []
Just unknownErr -> WriteResult
True
0
Nothing
n
(Just 0)
0
[]
[ ProtocolFailure
prevCount
@ -760,12 +760,12 @@ updateBlock ordered col (prevCount, docs) = do
let writeConcernResults =
case look "writeConcernError" doc of
Nothing -> WriteResult False 0 Nothing n [] [] []
Nothing -> WriteResult False 0 (Just 0) 0 [] [] []
Just (Doc err) -> WriteResult
True
0
Nothing
n
(Just 0)
0
[]
[]
[ WriteConcernFailure
@ -775,8 +775,8 @@ updateBlock ordered col (prevCount, docs) = do
Just unknownErr -> WriteResult
True
0
Nothing
n
(Just 0)
0
[]
[]
[ ProtocolFailure
@ -785,7 +785,9 @@ updateBlock ordered col (prevCount, docs) = do
++ (show unknownErr)]
let upsertedList = map docToUpserted $ fromMaybe [] (doc !? "upserted")
return $ mergeWriteResults writeErrorsResults writeConcernResults {upserted = upsertedList, nModified = at "nModified" doc}
liftIO $ putStrLn $ show doc
let successResults = WriteResult False n (doc !? "nModified") 0 upsertedList [] []
return $ foldl1' mergeWriteResults [writeErrorsResults, writeConcernResults, successResults]
interruptibleFor :: (Monad m, Result b) => Bool -> [a] -> (a -> m b) -> m [b]

View file

@ -316,6 +316,14 @@ spec = around withCleanDatabase $ do
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
, ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (3 :: Int)]
]
it "returns correct number of matched and modified" $ do
wireVersion <- getWireVersion
when (wireVersion > 1) $ do
_ <- db $ insertMany "testCollection" [["myField" =: "myValue"], ["myField2" =: "myValue2"]]
_ <- db $ insertMany "testCollection" [["myField" =: "myValue"], ["myField2" =: "myValue2"]]
res <- db $ updateMany "testCollection" [(["myField" =: "myValue"], ["$set" =: ["myField" =: "newValue"]], [MultiUpdate])]
nMatched res `shouldBe` 2
nModified res `shouldBe` (Just 2)
describe "delete" $ do
it "actually deletes something" $ do
@ -391,8 +399,6 @@ spec = around withCleanDatabase $ do
_ <- db $ deleteAll "bigCollection" $ map (\d -> (d, [])) docs
updatedResult <- db $ rest =<< find ((select [] "bigCollection") {project = ["_id" =: (0 :: Int)]})
length updatedResult `shouldBe` 0
describe "deleteAll" $ do
it "returns correct result" $ do
wireVersion <- getWireVersion
when (wireVersion > 1) $ do