Implement write concern for new version of insert
This commit is contained in:
parent
f28a76e953
commit
18ed370b90
1 changed files with 13 additions and 4 deletions
|
@ -418,11 +418,12 @@ insertAll_ :: (MonadIO m) => Collection -> [Document] -> Action m ()
|
||||||
-- ^ Same as 'insertAll' except don't return _ids
|
-- ^ Same as 'insertAll' except don't return _ids
|
||||||
insertAll_ col docs = insertAll col docs >> return ()
|
insertAll_ col docs = insertAll col docs >> return ()
|
||||||
|
|
||||||
insertCommandDocument :: [InsertOption] -> Collection -> [Document] -> Document
|
insertCommandDocument :: [InsertOption] -> Collection -> [Document] -> Document -> Document
|
||||||
insertCommandDocument opts col docs =
|
insertCommandDocument opts col docs writeConcern =
|
||||||
[ "insert" =: col
|
[ "insert" =: col
|
||||||
, "ordered" =: (KeepGoing `notElem` opts)
|
, "ordered" =: (KeepGoing `notElem` opts)
|
||||||
, "documents" =: docs
|
, "documents" =: docs
|
||||||
|
, "writeConcern" =: writeConcern
|
||||||
]
|
]
|
||||||
|
|
||||||
insert' :: (MonadIO m)
|
insert' :: (MonadIO m)
|
||||||
|
@ -431,7 +432,11 @@ insert' :: (MonadIO m)
|
||||||
insert' opts col docs = do
|
insert' opts col docs = do
|
||||||
p <- asks mongoPipe
|
p <- asks mongoPipe
|
||||||
let sd = P.serverData p
|
let sd = P.serverData p
|
||||||
let docSize = sizeOfDocument $ insertCommandDocument opts col []
|
mode <- asks mongoWriteMode
|
||||||
|
let writeConcern = case mode of
|
||||||
|
NoConfirm -> ["w" =: (0 :: Int)]
|
||||||
|
Confirm params -> params
|
||||||
|
let docSize = sizeOfDocument $ insertCommandDocument opts col [] writeConcern
|
||||||
chunks <- forM (splitAtLimit
|
chunks <- forM (splitAtLimit
|
||||||
(not (KeepGoing `elem` opts))
|
(not (KeepGoing `elem` opts))
|
||||||
(maxBsonObjectSize sd - docSize)
|
(maxBsonObjectSize sd - docSize)
|
||||||
|
@ -458,7 +463,11 @@ insertBlock opts col docs = do
|
||||||
write (Insert (db <.> col) opts docs')
|
write (Insert (db <.> col) opts docs')
|
||||||
return $ map (valueAt "_id") docs'
|
return $ map (valueAt "_id") docs'
|
||||||
else do
|
else do
|
||||||
doc <- runCommand $ insertCommandDocument opts col docs'
|
mode <- asks mongoWriteMode
|
||||||
|
let writeConcern = case mode of
|
||||||
|
NoConfirm -> ["w" =: (0 :: Int)]
|
||||||
|
Confirm params -> params
|
||||||
|
doc <- runCommand $ insertCommandDocument opts col docs' writeConcern
|
||||||
case (look "writeErrors" doc, look "writeConcernError" doc) of
|
case (look "writeErrors" doc, look "writeConcernError" doc) of
|
||||||
(Nothing, Nothing) -> return $ map (valueAt "_id") docs'
|
(Nothing, Nothing) -> return $ map (valueAt "_id") docs'
|
||||||
(Just err, Nothing) -> do
|
(Just err, Nothing) -> do
|
||||||
|
|
Loading…
Reference in a new issue