How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

How to delete all data for specific schema documents in Sanity?

10 repliesLast updated: Nov 29, 2025

Hello! I had data in my schema, changed the schema up to the point where it seems to have turned into a new schema and now I can not see the data anymore. Is there a way to delete only all data for specific schema documents?
AI Update

I understand your situation - you've changed your schema significantly and now can't see the old data in Studio. The good news is that the data isn't lost, it's just orphaned because the schema definition no longer matches. You can definitely delete all documents of a specific type.

Here's the recommended approach using Sanity CLI for bulk deletion:

Basic Setup:

First, make sure you have the necessary tools installed:

npm install -g @sanity/cli
npm install -g groq-cli

Delete documents by type:

You can delete all documents of a specific type with this command (split across lines for readability):

sanity documents query "*[_type == 'yourDocumentType'][0...20]._id" --apiVersion 2021-03-25 \
  | groq "*" -o ndjson \
  | xargs sanity documents delete

Replace 'yourDocumentType' with the actual _type of the documents you want to delete.

Important notes:

Alternative approach:

If you prefer, you can also write a migration script using the Sanity client that gives you more control over the deletion process.

Before deleting, you might want to export your data first as a backup:

sanity dataset export production backup.tar.gz

This way, if you realize you needed some of that data, you can still recover it.

Show original thread
10 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions