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

For bulk deletions, query for documents and delete them in a transaction. This ensures all deletions succeed or fail together:

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

Was this page helpful?