simcof
simcof9h ago

what is the fastest way to clear a table with 1m+ rows

our dataset is relatively small, most tables are 1-3m records. we needed to make a change to schema that required clearing all data in a few existing tables. using the dashboard clear table function is very slow. claude suggested a batch process which is also very slow: export const clearTableBatch = mutation({ args: { batchSize: v.optional(v.number()) }, handler: async (ctx, { batchSize = 100 }) => { const documents = await ctx.db .query("your_table_name") .take(batchSize);
for (const doc of documents) { await ctx.db.delete(doc._id); }
return { deleted: documents.length, hasMore: documents.length === batchSize }; }, }); what is the recommended way?
3 Replies
Convex Bot
Convex Bot9h ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Dev Italiya
Dev Italiya9h ago
npx convex import --table "$table" --replace -y --format jsonLines /dev/null Will delete all the data from the table
simcof
simcofOP9h ago
awesome! thank you so much

Did you find this page helpful?