Skip to content

Commit

Permalink
Update mongo repsert and replace calls (#1550)
Browse files Browse the repository at this point in the history
* 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-2.13.1.0

Co-authored-by: Matt Parsons <[email protected]>

---------

Co-authored-by: Matt Parsons <[email protected]>
  • Loading branch information
darycabrera and parsonsmatt authored Sep 13, 2024
1 parent e6a0a9f commit a2fdcde
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions persistent-mongoDB/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 9 additions & 9 deletions persistent-mongoDB/Database/Persist/MongoDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion persistent-mongoDB/persistent-mongoDB.cabal
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Expand Down

0 comments on commit a2fdcde

Please sign in to comment.