Assist with mutations
i want to add a document to the database but i want to make sure an exact match of that docment dosent already exist before adding it (i just want to make sure the userId dosent match the userID in an already existing document)
3 Replies
You can read before you write within a mutation and Convex guarantees the relevant db state won't change before the write completes. The mutation is a transaction.
Eg., if you query at the beginning of a mutation and at the end of the mutation, you will never get two different results. If the underlying data does change, Convex will rerun the mutation. Results of the mutation won't commit to the db until it can run without any underlying data change.
Mutations | Convex Developer Hub
Mutations insert, update and remove data from the database, check authentication
thank you @erquhart my problem is resolved