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

How to delete bulk documents from Sanity using CLI or Vision?

27 repliesLast updated: Dec 2, 2025

Hello Everyone
How to to delete bulk documents from sanity studio using CLI or vision ?
AI Update

There are two officially documented ways to bulk delete documents from Sanity:

The official CLI documents command provides a delete subcommand that can delete documents by ID:

# Delete single document
sanity documents delete myDocId

# Delete multiple documents by ID
sanity documents delete doc1 doc2 doc3

Important limitation: The CLI delete command works by document ID only. There's no built-in --query flag to delete by filter directly from the CLI.

2. Using @sanity/client with a query (For larger batches)

For deleting documents based on a GROQ query, you need to use the JavaScript client. There's an official recipe for this approach:

/**
 * THIS SCRIPT DELETES DATA!
 * 
 * To use:
 * 1. Save this as deleteDocsByFilter.js in your studio folder
 * 2. Backup your dataset: sanity dataset export
 * 3. Run: sanity exec deleteDocsByFilter.js --with-user-token
 */

import client from 'part:@sanity/base/client'

client
  .delete({query: '*[_type == "aDocumentType"][0...999]'})
  .then(console.log)
  .catch(console.error)

Important notes:

About Vision Plugin

The Vision plugin is great for testing queries, but it cannot perform deletions. Vision is read-only for querying - you must use the CLI or client for mutations.

Testing Your Query First

Before deleting, verify your query targets the right documents:

# Preview which documents will be affected
sanity documents query '*[_type == "myType"]._id'

This approach is documented in the official Sanity HTTP mutations reference, which confirms the delete mutation accepts a query parameter for bulk operations.

Show original thread
27 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