From a427c6f20189e538411798718e8dba0731d92044 Mon Sep 17 00:00:00 2001 From: Dary Cabrera Date: Wed, 11 Sep 2024 07:11:51 -0600 Subject: [PATCH 1/2] Update mongo repsert and replace calls Replace mongo driver save and replace calls with updateMany to restore correct behavior in MongoDB >=6.0 --- persistent-mongoDB/Database/Persist/MongoDB.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 From 6fe5fe3e67294fb88e13e5b489b84d32293142bb Mon Sep 17 00:00:00 2001 From: Dary Cabrera Date: Thu, 12 Sep 2024 10:48:42 -0600 Subject: [PATCH 2/2] persistent-mongoDB-2.13.1.0 Co-authored-by: Matt Parsons --- persistent-mongoDB/ChangeLog.md | 4 ++++ persistent-mongoDB/persistent-mongoDB.cabal | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/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