arianahaydnnn
arianahaydnnn7mo ago

Update status check

Hi, i wanna check update status this code. How can i do that. await ctx.db.replace(data._id, { ...data,flight_id: args.new_flight_id });
3 Replies
Michal Srb
Michal Srb7mo ago
You can also do:
await ctx.db.patch(data._id, { flight_id: args.new_flight_id });
await ctx.db.patch(data._id, { flight_id: args.new_flight_id });
What do you mean by "check update status" exactly?
arianahaydnnn
arianahaydnnnOP7mo ago
I need to give feedback on whether the data has been updated or not. How can I do that? What is the difference between replace and patch? Why should I use Patch?
Michal Srb
Michal Srb7mo ago
Patch vs replace: https://docs.convex.dev/database/writing-data#updating-existing-documents Whether it's been updated:
const existing = await ctx.db.get(data._id);
const changed = existing.flight_id !== args.new_flight_id;
await ctx.db.patch(data._id, { flight_id: args.new_flight_id });
return changed;
const existing = await ctx.db.get(data._id);
const changed = existing.flight_id !== args.new_flight_id;
await ctx.db.patch(data._id, { flight_id: args.new_flight_id });
return changed;
Writing Data | Convex Developer Hub
Mutations can insert, update, and

Did you find this page helpful?