✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

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– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?