It is known that we can update a MongoDB document atomically using the findAndModify method.
But how can we do it with a PanacheMongoRepository?
The PanacheMongoRepository interface has methods such as find and update, but nothing like findAndModify.
Is repository.update(updateDocument).where(queryDocument) an equivalent option? Is there a better way to do it?
Disclaimer: I am not familiar with
PanacheMongoRepositorysource code and how they implement things.However all these DB wrappers usually work in the same way, they just add syntax or notations about the native driver. Because they can't change the actual DB commands then it's usually safe to assume the same qualities are preserves across the same operators.
This means if a MongoDB update is atomic, most likely "PanacheMongo" update is also atomic. The code snippet you posted is the correct way to update and that's how you would execute it in MongoDB, just FYI
findAndModifyis deprecated. At the very least be wary of them.