Cannot remove property from document using patch mutation in Vision
Vision is a read-only GROQ query tool - it can't execute mutations. The Vision plugin in Sanity Studio is designed purely for testing and exploring GROQ queries, not for modifying data.
When you paste a mutation into Vision and run it, Vision is simply displaying your JSON back to you, not actually executing the mutation. That's why your property remains unchanged when you query for it afterward.
How to Actually Run Mutations
To execute mutations like your unset operation, you need to use one of these methods:
1. Use the Sanity CLI (recommended for one-off operations):
sanity documents query '*[_id == "<_id>"]' | \
sanity documents mutate --patch '{"id": "<_id>", "unset": ["property"]}'Or more directly with the sanity CLI:
echo '{"mutations": [{"patch": {"id": "<_id>", "unset": ["property"]}}]}' | \
sanity mutate2. Use the JavaScript client in your code:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token-with-write-permissions',
apiVersion: '2024-01-01'
})
await client.patch('<_id>')
.unset(['property'])
.commit()3. Use the HTTP Mutation API directly with a tool like curl or Postman:
curl -X POST "https://<project-id>.api.sanity.io/v2024-01-01/data/mutate/<dataset>" \
-H "Authorization: Bearer <your-token>" \
-H "Content-Type: application/json" \
-d '{"mutations": [{"patch": {"id": "<_id>", "unset": ["property"]}}]}'Draft vs. Published Documents
One common gotcha: if you're unsetting a property on a draft document, make sure your _id includes the drafts. prefix:
{
"patch": {
"id": "drafts.<_id>",
"unset": ["property"]
}
}When you query in Vision with *[_id == "<_id>"], you're querying the published version. If your document only exists as a draft, you'd need to query *[_id == "drafts.<_id>"] to see it.
Vision is perfect for testing your GROQ queries before using them in your application, but for mutations, you'll need one of the methods above with proper write permissions.
Show original thread1 reply
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.