
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGood news - you can still delete those documents even though you removed the schema! Since Sanity stores your content independently from your schema definitions, the data persists in your Content Lake even after you delete the schema code.
Here are your best options:
The simplest approach is to use the Vision plugin in your Sanity Studio:
*[_type == "yourSchemaType"]You can delete documents directly using the Sanity CLI with the sanity documents delete command:
# Delete a single document by ID
sanity documents delete <document-id>
# Query and delete multiple documents
sanity documents query '*[_type == "yourSchemaType"]' | jq -r '.[].\_id' | xargs -I {} sanity documents delete {}For bulk deletions (which sounds like your situation), you can write a Node.js script using @sanity/client:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token-with-write-access',
apiVersion: '2024-01-01',
useCdn: false
})
async function deleteDocuments() {
const query = '*[_type == "yourSchemaType"][0...100]'
const documents = await client.fetch(query)
if (documents.length === 0) {
console.log('No more documents to delete')
return
}
const transaction = client.transaction()
documents.forEach(doc => transaction.delete(doc._id))
await transaction.commit()
console.log(`Deleted ${documents.length} documents`)
// Run again if there are more
if (documents.length === 100) {
await deleteDocuments()
}
}
deleteDocuments()As mentioned in this community thread, you may need to run this in batches with cooldowns to avoid rate limiting. Process 100-200 documents at a time, and if you have thousands of documents, you might need to add a small delay between batches.
If you have other content you want to keep, you could also export your dataset without those documents and work from that clean dataset instead. This approach was suggested in the community thread as well - export everything except the documents you want to remove, then work from that dataset.
The key thing to remember is that in Sanity, your schema is just a validation layer - the actual content lives independently in the Content Lake, which is why you can still access and delete it even after removing the schema definition. Your data will continue to be returned by queries until you explicitly delete it.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store