
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, there are several ways to empty a dataset in Sanity! Here's what you can do:
The most straightforward approach is using the Sanity CLI documents delete command. You can delete documents by querying for their IDs and then deleting them.
Basic approach - delete documents in batches:
sanity documents query "*[_type == 'yourDocumentType'][0...100]._id" --api-version 2021-03-25 | \
xargs -n 100 sanity documents deleteTo delete ALL documents regardless of type:
sanity documents query "*[]._id" --api-version 2021-03-25 | \
xargs -n 100 sanity documents deleteImportant notes:
[0...100] limits the query to 100 documents at a time to avoid timeoutssanity documents delete doc1 doc2 doc3Based on this community guide, you can use a combination of CLI tools for faster deletion:
sanity documents query "*[_type == 'myDocument'][0...20]._id" --api-version 2021-03-25 | \
groq "*" -o ndjson | \
xargs sanity documents deleteThis requires installing groq-cli (npm install -g groq-cli) to convert the JSON output to newline-delimited format. Note that with large numbers of documents, you may experience timeouts, which is why the guide recommends batching (limiting to 20 documents at a time) and running the command multiple times.
You can also create a migration script for more control. Create a new migration:
npx sanity@latest migration create clearDatasetThen in your migration file, you need to explicitly delete documents using the proper API methods. Note that migrations work by returning mutation operations, not by returning undefined:
import {defineMigration} from 'sanity/migrate'
export default defineMigration({
title: 'Clear dataset',
migrate: {
document(doc, context) {
// Return a delete mutation for each document
// The migration system will handle executing these
return {delete: {id: doc._id}}
}
}
})Run it with dry-run first to verify:
npx sanity@latest migration run clearDataset --dry-runThen execute it:
npx sanity@latest migration run clearDatasetsanity dataset export if you might need the data later--dataset flag to explicitly target your dev dataset: sanity documents delete --dataset=development doc1 doc2For completely clearing a dev dataset, the CLI query + delete approach is usually the fastest and most reliable option. Just remember to run it in batches and repeat until all documents are gone!
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