
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your situation, the recommended approach for batch removing a deprecated field from your dataset is to use Sanity's migration tooling with the unset() function. Let me walk you through the best practice approach.
First, create a migration script:
npx sanity@latest migration create "Remove deprecated field"Then in the generated migrations/your-migration-name/index.ts file, use this pattern:
import {defineMigration, at, unset} from 'sanity/migrate'
export default defineMigration({
title: 'Remove deprecated field',
documentTypes: ['yourDocumentType'], // specify the document type(s)
migrate: {
document(doc, context) {
// Remove the deprecated field
return at('deprecatedFieldName', unset())
}
}
})The key to success is following this process:
sanity migration run your-migration-nameThis shows you what would happen without making actual changes.
sanity migration run your-migration-name --dataset <your-dataset-name>The defineMigration API handles several important things automatically:
If you need to remove multiple deprecated fields at once:
migrate: {
document(doc, context) {
return [
at('deprecatedField1', unset()),
at('deprecatedField2', unset()),
at('nested.deprecatedField', unset())
]
}
}If you're still not seeing success:
documentTypes array matches exactly with your schema type namesat() must match the exact field name in your documents'parent.child.fieldName'The migration tooling is specifically designed for this batch patch use case and handles all the complexity of batching mutations automatically, making it more reliable than manual patching scripts. If you're still experiencing issues after following this pattern, double-check that your field names and document types exactly match what's in your dataset.
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