Skip to content

Commit

Permalink
Update mongo deletion calls
Browse files Browse the repository at this point in the history
Replace the mongo driver's delete calls with deleteMany to restore
correct behavior with Mongo 6.0 while preserving compatibility
with Mongo 5.0.
  • Loading branch information
darycabrera committed Aug 26, 2024
1 parent c6fd4cb commit 3a2ca9f
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions persistent-mongoDB/Database/Persist/MongoDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module Database.Persist.MongoDB
) where

import Control.Exception (throw, throwIO)
import Control.Monad (forM_, liftM, unless, (>=>))
import Control.Monad (forM_, liftM, unless, (>=>), void)
import Control.Monad.IO.Class (liftIO)
import qualified Control.Monad.IO.Class as Trans
import Control.Monad.IO.Unlift (MonadUnliftIO, withRunInIO)
Expand Down Expand Up @@ -562,10 +562,9 @@ instance PersistStoreWrite DB.MongoContext where
return ()

delete k =
DB.deleteOne DB.Select {
DB.coll = collectionNameFromKey k
, DB.selector = keyToMongoDoc k
}
void $ DB.deleteMany
(collectionNameFromKey k)
[(keyToMongoDoc k, [DB.SingleRemove])]

update _ [] = return ()
update key upds =
Expand Down Expand Up @@ -608,10 +607,9 @@ instance PersistUniqueRead DB.MongoContext where

instance PersistUniqueWrite DB.MongoContext where
deleteBy uniq =
DB.delete DB.Select {
DB.coll = collectionName $ dummyFromUnique uniq
, DB.selector = toUniquesDoc uniq
}
void $ DB.deleteMany
(collectionName $ dummyFromUnique uniq)
[(toUniquesDoc uniq, [DB.SingleRemove])]

upsert newRecord upds = do
uniq <- onlyUnique newRecord
Expand Down Expand Up @@ -703,11 +701,10 @@ instance PersistQueryWrite DB.MongoContext where
, DB.selector = filtersToDoc filts
} $ updatesToDoc upds

deleteWhere filts = do
DB.delete DB.Select {
DB.coll = collectionName $ dummyFromFilts filts
, DB.selector = filtersToDoc filts
}
deleteWhere filts =
void $ DB.deleteMany
(collectionName $ dummyFromFilts filts)
[ (filtersToDoc filts, [])]

instance PersistQueryRead DB.MongoContext where
count filts = do
Expand Down

0 comments on commit 3a2ca9f

Please sign in to comment.