Is there an easy way of clearing unwanted published items?

5 replies
Last updated: Oct 30, 2020
HI I have published once but my data shows an array?
"result":[2 items
0:{6 items
"_createdAt":"2020-10-30T07:44:59Z"
"_id":"932ebb41-cf8d-463d-9ad9-6e4c88588b54"
"_rev":"XNtMa4Y66vmVFnyOJAoV3C"
"_type":"siteSettings"
"_updatedAt":"2020-10-30T08:08:55Z"
"owner":{4 items
"facebook":"@facebook"
"instagram":"@instagram"
"name":"Amy Robers"
"twitter":"@twitter"
}
}
1:{8 items
"_createdAt":"2020-10-30T11:51:03Z"
"_id":"siteSettings"
"_rev":"XNtMa4Y66vmVFnyOJEK8AQ"
"_type":"siteSettings"
"_updatedAt":"2020-10-30T15:53:17Z"
"name":"Amy"
"person":{3 items
"facebook":"<https://yourfacebookurl/>"
"instagram":"<https://yourinstagramurl/>"
"twitter":"<https://yourtwitterurl/>"
}
"website":"<http://yogawithamy.com|yogawithamy.com>"
}
]
How can I clear that first array? Thanks
AI Update

Looking at your data, you have two documents of type siteSettings with different _id values:

  1. "932ebb41-cf8d-463d-9ad9-6e4c88588b54" (created first)
  2. "siteSettings" (created later)

This is a common issue when setting up singleton documents - you've accidentally created multiple instances of what should be a single-instance document type.

To fix this, you need to delete the duplicate document. Here's how:

  1. Go to your Sanity Studio and navigate to Vision (the query tool)

  2. Run this query to verify which document you want to keep:

    *[_type == "siteSettings"]
  3. Delete the unwanted document (likely the first one with the UUID). You can do this by:

    • Finding it in your Studio content list and deleting it manually, OR
    • Using the Vision tool with this mutation:
    // Delete by ID
    sanity.delete('932ebb41-cf8d-463d-9ad9-6e4c88588b54')

Based on your data, you probably want to keep the second one (_id: "siteSettings") since it has your actual content (name: "Amy", website, etc.) and delete the first one.

To prevent this from happening again, configure your siteSettings as a proper singleton in your sanity.config.ts:

export default defineConfig({
  // ... other config
  schema: {
    types: schemaTypes,
    templates: (templates) =>
      templates.filter(({ schemaType }) => schemaType !== 'siteSettings')
  },
  document: {
    actions: (input, context) =>
      context.schemaType === 'siteSettings'
        ? input.filter(({ action }) => !['duplicate', 'delete', 'unpublish'].includes(action))
        : input
  }
})

This prevents creating additional instances through the "New document" menu and removes dangerous actions like duplicate/delete from the singleton document.

Show original thread
5 replies
Looks like you’re querying
_type == "siteSettings"
and you’ve published several siteSettings documents already. Try
*[_id == "siteSettings"][0]
instead
Thanks! Is there an easy way of clearing unwanted published items?
Hi James, you could run
sanity documents delete <id>
to delete a single document.
Hi James, you could run
sanity documents delete <id>
to delete a single document.
Thanks for the help . Much appreciated. Command line did the trick ⛑️

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?