Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Hey all - what’s the quickest way to batch delete all documents of a certain type? It looks like the `sanity` cli tool allows deletion of documents by ID but no ability to...

4 replies
Last updated: Jan 29, 2021

Hey all - what’s the quickest way to batch delete all documents of a certain type? It looks like the

sanity
cli tool allows deletion of documents by ID but no ability to delete by query?

Jan 29, 2021, 1:04 AM

I think you can (but don't use the CLI myself). See "Deleting multiple documents by query" here: https://www.sanity.io/docs/http-mutations

Jan 29, 2021, 2:21 AM

Hey

user A
thanks! I actually managed to just do a
sanity documents query
call to grab all of the relevant document IDs, pulled them into a text doc to massage the response down to space-separated IDs, then put them back into
sanity documents delete …
and it worked a charm 😄

Jan 29, 2021, 2:22 AM

Maybe not the proper programmatic way to do it, but good enough for what I need for now

Jan 29, 2021, 2:23 AM

Nice. Hey, if it worked, it was the right way. 🥳

Jan 29, 2021, 2:24 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.