Knut Melvær
Knut is a principal developer marketing manager at Sanity.io
Migration script for deleting documents based on a GROQ filter
This recipe is for an older version of Sanity Studio (v2), which is deprecated.
Learn how to migrate to the new Studio v3 →/**
* THIS SCRIPT DELETES DATA!
*
* To use this script:
* 1. Put this script in your studio-folder
* 2. Write a GROQ filter that outputs the documents you want to delete
* 3. Run `sanity dataset export` to backup your dataset before deleting a bunch of documents
* 4. Run `sanity exec deleteDocsByFilter.js --with-user-token` to delete the documents
*
* NOTE: For the time being you should not delete more than ~1000 documents in one transaction. This will change in the future.
* See docs:https://www.sanity.io/docs/http-api/http-mutations#deleting-multiple-documents-by-query
*/
import client from 'part:@sanity/base/client'
client
.delete({query: '*[_type == "aDocumentType"][0...999]'})
.then(console.log)
.catch(console.error)This script lets you delete documents based on a GROQ filter. It can be run in a studio folder using sanity exec deleteDocsByFilter.js --with-user-token. Note that this script deletes data, and it can be wise to test your query and export your dataset before running this.
Knut is a principal developer marketing manager at Sanity.io
Automatically track when content was first published with a timestamp that sets once and never overwrites, providing reliable publication history for analytics and editorial workflows.
Go to First Published Timestamp FunctionAI-powered automatic tagging for Sanity blog posts that analyzes content to generate 3 relevant tags, maintaining consistency by reusing existing tags from your content library.
Go to Automatically tag blog postsThis can be used for blogs or articles where you want to possibly display next and previous article buttons
Go to Get current post, previous post, and next postHow to automatically generate linked headings with a custom serializer
Go to Anchored Headings for Portable Text