Steps to empty and copy datasets in Sanity.io discussed
11 replies
Last updated: Jun 24, 2024
F
Hi Team,Is there any way to empty dataset? Just have Dev dataset but remove all the content from it?
Jun 17, 2024, 1:56 PM
F
Just to give you more context,I am trying to copy my prod dataset to dev and want to empty dev dataset first before copying prod to dev to ensure there is no old data in dev.
I will be using
I will be using
sanity dataset export productionto export and then import in dev but is there any way I can empty Dev dataset?
Jun 17, 2024, 1:57 PM
N
Hey User!
Easy way: Delete the dataset and then re-create it
Slightly harder way: Use the api to get every document and delete it. https://www.sanity.io/guides/bulk-deletion-using-sanity-cli << I would use a query like:
to select every document. The latter part of that query converts it to NDJSON so you don't run into API limits and delete a ton of stuff in a row
Easy way: Delete the dataset and then re-create it
Slightly harder way: Use the api to get every document and delete it. https://www.sanity.io/guides/bulk-deletion-using-sanity-cli << I would use a query like:
sanity documents query "*[_type !== null]" --apiVersion 2021-03-25 | groq "*" -o ndjson | xargs sanity documents delete
Jun 17, 2024, 5:40 PM
N
Ooooo even fancier
Jun 17, 2024, 5:49 PM
F
Thank you both. This is really helpful. Just a dumb question I guess,If I delete the dataset and recreate it, as long as it is in my dataset limit, I wont get charge right?
I can re-create it with existing prod data, right? Do we have any document for this?
I can re-create it with existing prod data, right? Do we have any document for this?
Jun 17, 2024, 5:52 PM
F
Also if I delete dataset, is there anything I should be careful or consider in terms of maybe data or affect on my website?
Jun 17, 2024, 5:55 PM
N
I'll have rd correct me if I'm wrong, 2 ways to do your second question:1. export prod database > create new dev dataset > import data from prod
2. Or, run copy, like the docs below, honestly my vote is this
https://www.sanity.io/docs/dataset#9d4339524663 ^^ dataset docs here
2. Or, run copy, like the docs below, honestly my vote is this
https://www.sanity.io/docs/dataset#9d4339524663 ^^ dataset docs here
Jun 17, 2024, 5:55 PM
F
Aha yes, copy is good one. Looks easier than 1st approach.
Jun 17, 2024, 5:56 PM
F
user D
user M
I tried to copy dataset from Prod to staging but I got an error saying, my plan does not support this advance feature.If that is the case then i assume, I only have one way to copy all data from prod to staging.
1. sanity dataset export prod
2. delete staging
3. sanity dataset import path-of-prod-backup staging
Jun 24, 2024, 7:31 PM
F
I have updated my above question as I found the issue in my query, instead of,staging.tar, I should have done staging.tar.gz
Jun 24, 2024, 7:47 PM
Yes, copying a dataset is an Enterprise feature. What you outlined is the correct way forward!
Jun 24, 2024, 7:50 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.