APIs and SDKs

Deleting documents with @sanity/client

Learn how to delete documents by ID or by query using the Sanity JavaScript client.

The @sanity/client library provides methods for deleting documents individually by ID or in bulk using a query. This guide covers both approaches.

Prerequisites

Deleting requires an authenticated client with a write token. See Getting started with @sanity/client for setup instructions.

Delete by ID

Use client.delete() to remove a single document by its ID:

Delete by query

To delete every document that matches a GROQ query in one request, pass an object with a query and optional params to client.delete(). This is the recommended way to delete by query. A single query-based mutation affects at most 10,000 documents:

To review the matching documents before you delete them, fetch their IDs first, then delete them in a transaction. All deletions in a transaction succeed or fail together:

The fetch-then-delete example uses client.transaction() to delete all matching documents atomically. Learn more about transactions in Transactions.

Was this page helpful?