How can I delete a document in sanity studio?

2 replies
Last updated: Sep 29, 2020
Hi! how can I delete a document in sanity studio?
AI Update

There are a few ways to delete documents in Sanity Studio depending on your needs:

Deleting in Sanity Studio (UI)

The most straightforward method is through the Studio interface:

  1. Open the document you want to delete in Sanity Studio
  2. Look for the three-dot menu (⋯) or arrow icon to the right of the Publish button in the top-right corner
  3. Click it and select "Delete" from the dropdown menu
  4. Confirm the deletion when prompted

This is part of the document actions system in Sanity Studio. The delete action is available by default for all documents unless it's been explicitly disabled through custom document actions configuration.

Deleting via Sanity CLI

If you need to delete documents programmatically or in bulk, you can use the Sanity CLI:

sanity documents delete <document-id>

You'll need to have the Sanity CLI installed (npm install -g @sanity/cli) and be authenticated to your project.

For bulk deletions, you can combine GROQ queries with the delete command:

sanity documents query "*[_type == 'yourType']" | sanity documents delete

Programmatic Deletion

You can also delete documents programmatically using the Sanity client:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  token: 'your-token',
  apiVersion: '2024-01-01'
})

await client.delete('document-id')

Troubleshooting

If you don't see the delete option in the Studio menu, it could be because:

  • Custom document actions have been configured to hide it (especially common with singleton documents)
  • You don't have the necessary permissions based on your role configuration

The delete action may be filtered out for certain document types to prevent accidental deletion of critical content like site settings or configuration documents.

Show original thread
2 replies
It should be a arrow icon to the right of the publish button, where you find delete, and a few more options
found it! Thanks!

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.

Was this answer helpful?