RayyR
Convex Community2y ago
6 replies
Rayy

How to empty an optional field in the table?

  chatbook: defineTable({
    userId: v.id("users"),
    url: v.string(),
    type: v.optional(v.string()),
    title: v.optional(v.string()),
    length: v.optional(v.number()),
    chat: v.optional(v.array(Message)),
    embeddingId: v.optional(v.array(v.id("chatEmbeddings"))),
  }).index("by_embedding", ["embeddingId"]),


This is my schema and I want to empty the chat field when this mutation is called.

export const deleteMessageHistory = mutation({
  args: { chatId: v.id("chatbook") },
  handler: async (ctx, args) => {
    await ctx.db.replace(args.chatId, {chat: null})
  },
});


I cannot initialise null to it since I am getting validation error, so how can I achieve this?
Was this page helpful?