Is there a convenient way to get the updated document after using the db.patch method?
In my project the method returns undefined instead of the updated object. Maybe this is the expected behavior. The docs aren't explicit on what the method returns. Am I missing something
5 Replies
hi! the docs for patch here: https://docs.convex.dev/api/interfaces/server.DatabaseWriter#patch
Interface: DatabaseWriter | Convex Developer Hub
server.DatabaseWriter
specify that patch returns
Promise<void>
aka it returns nothing. so short answer, nope, it does not return the updated document
you'd need to db.get
after the patch. or just turn the whole pass into a db.get
/ (modify document) / db.replace
, in which case you'd have the updated document in handOkay thanks Jamie, appreciated
As a reminder, since it's in a transaction with Convex's strong isolation guarantees, if you have the object before the patch (e.g. via
db.get
) and manually patch it, you'll get the same result as doing db.get
after the patch.Thanks for the explanation