ibrahimyaacobI
Convex Community12mo ago
31 replies
ibrahimyaacob

DELETE_MISSING_KEY error on aggregate.trigger() on trigger (convex helper)

im trying to create a count aggregations on an existing table.
i manage to run the migration as per below

export const backfillAggregatesMigration = migrations.define({
  table: "socialPostComments",
  customRange: (q) => q.withIndex("unreadStatus", (q) => q.eq("isRead", false)),
  migrateOne: async (ctx, doc) => {
    await unreadCommentCountByStatusTable.insertIfDoesNotExist(ctx, doc);
    await unreadCommentCountByAssignedToTable.insertIfDoesNotExist(ctx, doc);
    await unreadCommentCountByAccountTable.insertIfDoesNotExist(ctx, doc);
  },
});

and so far the backfill works fine. which i can see the aggregates count numbers are correct.
but when i add the code to my trigger function (to update the triggers automatically).

export default async function socialPostCommentTriggers(
  ctx: TriggerCtx,
  triggerArgs: TriggerArgs<"socialPostComments">,
) {
  const { newDoc, oldDoc, operation } = triggerArgs;

  // testing triggers
  const aggregateTriggerForStatus = unreadCommentCountByStatusTable.trigger();
  const aggregateTriggerForAssignedTo =
    unreadCommentCountByAssignedToTable.trigger();
  const aggregateTriggerForAccount = unreadCommentCountByAccountTable.trigger();

  await aggregateTriggerForStatus(ctx, triggerArgs);
  await aggregateTriggerForAssignedTo(ctx, triggerArgs);
  await aggregateTriggerForAccount(ctx, triggerArgs);
}


i got the error above.
image.png
Was this page helpful?