Discussion on deleting a collection and resolving reference errors in Sanity.io
17 replies
Last updated: Oct 18, 2022
M
Hi Alli have problem to delete a collection
i run this command
but i got this error
i run this command
sanity documents query "*[_type == 'cruise_list'][0...20]._id" --apiVersion v1 | groq "*" -o ndjson | xargs sanity documents delete
Error: Failed to delete documents: Mutation(s) failed with 1 error(s)
Oct 18, 2022, 6:18 PM
Hi
user Y
. Your note about references is key. Strong references (the default) cannot point at documents that don’t exist, which includes those that have been deleted or not yet created. Before you can delete this document, those references will need either to be removed or made weak.Oct 18, 2022, 6:48 PM
M
Hi
user A
when i created this collection i did as weakOct 18, 2022, 6:50 PM
M
this an example
{"id": 1, "voyageID": 156, "ship": "Crystal Serenity", "shipCod": {"_type": "reference", "_ref": "ships_1"}, "cruiseLine": "Crystal Cruises", "cruiseLineCod": "CYC", "voyageNumber": "SI20221011007", "voyageName": "Cruising the Greek Islands of the Southern Aegean \u2013 with Smithsonian Journeys\r\n", "description": "None", "duration": 7, "embarkDate": "2022-10-11 00:00:00", "embarkPort": "Athens (Piraeus)", "debarkDate": "2022-10-18 00:00:00", "debarkPort": "Athens (Piraeus)", "destinationID": {"_type": "reference", "_ref": "destinations_7"}, "isAvailable": "True", "price": 9000.0, "currency": "USD", "priceTypeName": "Crystal Entry Level Fare", "priceTypeCod": "DPT", "voyageType": "Ocean Cruise", "embarkPortCod": {"_type": "reference", "_ref": "ports_933"}, "debarkPortCod": {"_type": "reference", "_ref": "ports_933"}, "previousVoyageID": {"_type": "reference", "_ref": "cruise_list_1"}, "nextVoyageID": {"_type": "reference", "_ref": "cruise_list_1"}, "map": "None", "title": "None", "voyageDescription": "None", "mapSVG": "None", "mapPNG": "None", "mapPNG2": "None", "mapPNG3": "None", "images1": "None", "_id": "cruise_list_1", "_type": "cruise_list", "_weak": true}
Oct 18, 2022, 6:50 PM
Weak references would have
_weak: truein the JSON, but several of those references appear not to.
Oct 18, 2022, 6:58 PM
Actually, I could just be reading it wrong. I’m on mobile, so I’ll take a closer look when I’m back online.
Oct 18, 2022, 6:59 PM
M
i thought that
_weakwas global
Oct 18, 2022, 6:59 PM
M
so i need to set on each filed
Oct 18, 2022, 6:59 PM
M
in the json that i show you i just set
"_weak": true1 time for all those data
Oct 18, 2022, 7:32 PM
M
is not enough?
Oct 18, 2022, 7:32 PM
M
the json that i posted is my data that i try to import into sanity
Oct 18, 2022, 7:58 PM
M
instead on the schema js files
Oct 18, 2022, 7:58 PM
M
i have for all reference
Oct 18, 2022, 7:58 PM
M
{ name: 'voyageNumber', type: 'reference', title: 'voyageNumber', weak: true, to: [{ type: 'cruise_list' }] },
Oct 18, 2022, 7:58 PM
M
weak: true
Oct 18, 2022, 7:59 PM
Any changes to a schema will never change your content, so you’d need to actually set . Remember to get
_weak: truein the document JSON itself. One way to do this is from your command line, running
sanity documents create --replace --watch --id "DOCUMENT_ID"
drafts.DOCUMENT_IDas well, if there is one.
Oct 18, 2022, 8:30 PM
M
perfect clear thanks so much for your help
Oct 18, 2022, 9:15 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.