
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeNo, you cannot override or force delete documents that have strong references from other documents. This is by design for referential integrity protection in Sanity.
However, you have several options to handle this situation:
If you want to allow deletion regardless of references, you can modify your schema to use weak references by adding weak: true:
{
name: 'someField',
type: 'reference',
to: [{type: 'work'}],
weak: true // Allows deletion even if referenced
}Important: Just changing this property won't automatically update existing references in your data store.
You can filter your query to only delete documents that don't have incoming references:
const posts = await client.fetch(`
*[_type == 'work' && count(*[references(^._id)]) == 0][0...500]
{ title, _id, _rev }
`)To see which documents are preventing deletion, catch the error and query for referencing documents:
posts.forEach((post) => {
queue.add(() =>
client
.delete(post._id)
.catch((err) => {
console.error('Delete failed: ', err.message)
client.fetch('*[references($id)]._id', { id: post._id })
.then((results) => {
console.log('The following documents reference this document:')
results.forEach((id) => console.log(' ', id))
})
})
)
})The proper approach is to delete or update the documents that reference your target documents first, then delete the target documents themselves.
The strong reference protection is intentional—it prevents orphaned references and maintains data integrity in your content lake. If you truly need to bulk delete documents with references, you'll need to handle the referencing documents first, either by:
If you're trying to roll back mutations (as mentioned in the linked discussion), consider using the unset operation to remove specific fields rather than deleting entire documents.
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