Rayy
Rayy2y ago

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"]),
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})
},
});
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?
5 Replies
Michal Srb
Michal Srb2y ago
await ctx.db.patch(args.chatId, {chat: undefined})
Rayy
RayyOP2y ago
Ah, I missed that. Anyway, thanks @Michal Srb
ian
ian2y ago
Also from the dashboard you can try out the bulk edit feature, setting the patch to be undefined for that field hopefully works
Rayy
RayyOP2y ago
Yeah it did work.

Did you find this page helpful?