Skip to content

Commit

Permalink
Update mongo repsert and replace calls
Browse files Browse the repository at this point in the history
Replace mongo driver save and replace calls with updateMany to
restore correct behavior in MongoDB >=6.0
  • Loading branch information
darycabrera committed Sep 11, 2024
1 parent e6a0a9f commit a427c6f
Showing 1 changed file with 9 additions and 9 deletions.
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

0 comments on commit a427c6f

Please sign in to comment.