Trying to delete a field from template in Sanity IO

69 views Asked by At

I have a field that I added but it is unnecessary. I ran a mutation to set the boolean value but now I want to remove the field entirely from the template.

What I tried to do, below, was a variation on the mutation I ran, this was also based on this post, https://www.sanity.io/schemas/batch-remove-a-field-3841897a, which I read but would not run for me instead producing all kinds of dependency issues that I did not want to waste time on.

curl 'https://<client_id>.api.sanity.io/v2021-06-07/data/mutate/<process.env>' \
    -H 'Authorization: Bearer <token>' \
    -H 'Content-Type: application/json' \
    --data-binary '{"mutations": [{"patch": {"query": "*[_type == \"contribution\"]"}, "unset": "published"}]}'

What is the easiest way to mass remove this published field I added from the contribution template (it has already been removed from the schema)?

Just to be totally clear, this is what I am trying to get rid of without having to view every single entry

enter image description here

1

There are 1 answers

4
ADITYA On

Assuming your schema is structured somewhat like this:

{
  "name": "contribution",
  "type": "document",
  "fields": [
    // Other fields...
    {
      "name": "published",
      "type": "boolean",
      "description": "Indicates if the contribution is published or not"
    },
    // Other fields...
  ]
}

You can remove the "published" field from your schema using the Sanity.io CLI.

npm install -g @sanity/cli
sanity schema removeField contribution.published
sanity deploy