Add test and fix for updateMany nMatched and nModified
This commit is contained in:
parent
50b7fef240
commit
a1e19379f6
2 changed files with 20 additions and 12 deletions
|
@ -744,13 +744,13 @@ updateBlock ordered col (prevCount, docs) = do
|
||||||
let n = fromMaybe 0 $ doc !? "n"
|
let n = fromMaybe 0 $ doc !? "n"
|
||||||
let writeErrorsResults =
|
let writeErrorsResults =
|
||||||
case look "writeErrors" doc of
|
case look "writeErrors" doc of
|
||||||
Nothing -> WriteResult False 0 Nothing n [] [] []
|
Nothing -> WriteResult False 0 (Just 0) 0 [] [] []
|
||||||
Just (Array err) -> WriteResult True 0 Nothing n [] (map (anyToWriteError prevCount) err) []
|
Just (Array err) -> WriteResult True 0 (Just 0) 0 [] (map (anyToWriteError prevCount) err) []
|
||||||
Just unknownErr -> WriteResult
|
Just unknownErr -> WriteResult
|
||||||
True
|
True
|
||||||
0
|
0
|
||||||
Nothing
|
(Just 0)
|
||||||
n
|
0
|
||||||
[]
|
[]
|
||||||
[ ProtocolFailure
|
[ ProtocolFailure
|
||||||
prevCount
|
prevCount
|
||||||
|
@ -760,12 +760,12 @@ updateBlock ordered col (prevCount, docs) = do
|
||||||
|
|
||||||
let writeConcernResults =
|
let writeConcernResults =
|
||||||
case look "writeConcernError" doc of
|
case look "writeConcernError" doc of
|
||||||
Nothing -> WriteResult False 0 Nothing n [] [] []
|
Nothing -> WriteResult False 0 (Just 0) 0 [] [] []
|
||||||
Just (Doc err) -> WriteResult
|
Just (Doc err) -> WriteResult
|
||||||
True
|
True
|
||||||
0
|
0
|
||||||
Nothing
|
(Just 0)
|
||||||
n
|
0
|
||||||
[]
|
[]
|
||||||
[]
|
[]
|
||||||
[ WriteConcernFailure
|
[ WriteConcernFailure
|
||||||
|
@ -775,8 +775,8 @@ updateBlock ordered col (prevCount, docs) = do
|
||||||
Just unknownErr -> WriteResult
|
Just unknownErr -> WriteResult
|
||||||
True
|
True
|
||||||
0
|
0
|
||||||
Nothing
|
(Just 0)
|
||||||
n
|
0
|
||||||
[]
|
[]
|
||||||
[]
|
[]
|
||||||
[ ProtocolFailure
|
[ ProtocolFailure
|
||||||
|
@ -785,7 +785,9 @@ updateBlock ordered col (prevCount, docs) = do
|
||||||
++ (show unknownErr)]
|
++ (show unknownErr)]
|
||||||
|
|
||||||
let upsertedList = map docToUpserted $ fromMaybe [] (doc !? "upserted")
|
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]
|
interruptibleFor :: (Monad m, Result b) => Bool -> [a] -> (a -> m b) -> m [b]
|
||||||
|
|
|
@ -316,6 +316,14 @@ spec = around withCleanDatabase $ do
|
||||||
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
|
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
|
||||||
, ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (3 :: 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
|
describe "delete" $ do
|
||||||
it "actually deletes something" $ do
|
it "actually deletes something" $ do
|
||||||
|
@ -391,8 +399,6 @@ spec = around withCleanDatabase $ do
|
||||||
_ <- db $ deleteAll "bigCollection" $ map (\d -> (d, [])) docs
|
_ <- db $ deleteAll "bigCollection" $ map (\d -> (d, [])) docs
|
||||||
updatedResult <- db $ rest =<< find ((select [] "bigCollection") {project = ["_id" =: (0 :: Int)]})
|
updatedResult <- db $ rest =<< find ((select [] "bigCollection") {project = ["_id" =: (0 :: Int)]})
|
||||||
length updatedResult `shouldBe` 0
|
length updatedResult `shouldBe` 0
|
||||||
|
|
||||||
describe "deleteAll" $ do
|
|
||||||
it "returns correct result" $ do
|
it "returns correct result" $ do
|
||||||
wireVersion <- getWireVersion
|
wireVersion <- getWireVersion
|
||||||
when (wireVersion > 1) $ do
|
when (wireVersion > 1) $ do
|
||||||
|
|
Loading…
Reference in a new issue