diff --git a/persistent-mongoDB/ChangeLog.md b/persistent-mongoDB/ChangeLog.md index 7bf562515..6af565eda 100644 --- a/persistent-mongoDB/ChangeLog.md +++ b/persistent-mongoDB/ChangeLog.md @@ -1,5 +1,9 @@ # Changelog for persistent-mongoDB +## 2.13.1.0 + +* Restore update write concern behavior with MongoDB Driver for MongoDB >= 6.0 [#1550](https://github.com/yesodweb/persistent/pull/1550) + ## 2.13.0.2 * Fix behavioral compatibility with MongoDB Driver for MongoDB >= 6.0 [#1545](https://github.com/yesodweb/persistent/pull/1545) diff --git a/persistent-mongoDB/Database/Persist/MongoDB.hs b/persistent-mongoDB/Database/Persist/MongoDB.hs index 71cd23557..679ce540a 100644 --- a/persistent-mongoDB/Database/Persist/MongoDB.hs +++ b/persistent-mongoDB/Database/Persist/MongoDB.hs @@ -371,10 +371,6 @@ queryByKey :: (PersistEntity record, PersistEntityBackend record ~ DB.MongoConte => Key record -> DB.Query queryByKey k = (DB.select (keyToMongoDoc k) (collectionNameFromKey k)) {DB.project = projectionFromKey k} -selectByKey :: (PersistEntity record, PersistEntityBackend record ~ DB.MongoContext) - => Key record -> DB.Selection -selectByKey k = DB.select (keyToMongoDoc k) (collectionNameFromKey k) - updatesToDoc :: (PersistEntity record, PersistEntityBackend record ~ DB.MongoContext) => [Update record] -> DB.Document updatesToDoc upds = map updateToMongoField upds @@ -554,12 +550,16 @@ instance PersistStoreWrite DB.MongoContext where insertKey k record = DB.insert_ (collectionName record) $ entityToInsertDoc (Entity k record) - repsert k record = DB.save (collectionName record) $ - documentFromEntity (Entity k record) + repsert k record = + void $ DB.updateMany + (collectionName record) + [(keyToMongoDoc k, documentFromEntity (Entity k record), [DB.Upsert])] - replace k record = do - DB.replace (selectByKey k) (recordToDocument record) - return () + replace k record = + -- replace a single matching document + void $ DB.updateMany + (collectionNameFromKey k) + [(keyToMongoDoc k, recordToDocument record, [])] delete k = void $ DB.deleteMany diff --git a/persistent-mongoDB/persistent-mongoDB.cabal b/persistent-mongoDB/persistent-mongoDB.cabal index 2c6de362b..6bc2b02e1 100644 --- a/persistent-mongoDB/persistent-mongoDB.cabal +++ b/persistent-mongoDB/persistent-mongoDB.cabal @@ -1,5 +1,5 @@ name: persistent-mongoDB -version: 2.13.0.2 +version: 2.13.1.0 license: MIT license-file: LICENSE author: Greg Weber