IamtheFutureI
Convex Community17mo ago
2 replies
IamtheFuture

Batch Patch Error

why is this throwing error

export const updateFeaturedProducts = mutation({
  args: {
    products: v.array(v.id("products")),
  },
  handler: async (ctx, args) => {
    await checkIfAdmin(ctx);

    // Filter out any undefined values
    const validProducts = args.products.filter((id) => id !== undefined);

    return Promise.all(
      validProducts.map(async (id) => {
        console.log(id);
        await ctx.db.patch(id, { isFeatured: false });
      }),
    );,
    );
  },
});

error:

[CONVEX M(products:updateFeaturedProducts)] [Request ID: 583339ec3107f9e8] Server Error
Uncaught Error: undefined is not a valid Convex value (present at path [0] in original object ["undefined"]). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:287:6)
Was this page helpful?