How to find documents containing bad data in a nested custom component using Groq query.
5 replies
Last updated: Apr 3, 2022
O
We have managed to import some bad data in some documents, in a nested custom component, and I am trying to write a groq query to find what documents contain bad data.The problem is that some articles have ended up with a mark on a custom block, which ends up giving an error when we try to render it, because the marks aren’t a part of the schema. an example of such a bad block:
this lives in a nested type, so the structure is something like this
and I am trying to find all documents containing
but that ends up returning documents where there are no
and similar things, but they all end up either matching 0 documents, or too many documents. any pointers on how I can achieve this filter, or is it easier to just fetch all and manually go through them in javascript?
{ "_key": "afd98068bfc1", "_type": "bilde", "altText": "", "caption": "", "image": { "_type": "image", "asset": { "_ref": "image-b3d77a3ad3970d959d3bf83d6d2c02ad320cbb71-1000x681-jpg", "_type": "reference" } }, "marks": [ { "_key": "3c540f80b489", "_type": "link", "href": "<https://some-url>" } ] },
brodtekst[_type == 'hjelpeartikkel.expandCollapse'].innhold[_type == 'bilde']
bildewith the bad
marksarray, but I can’t seem to find the right filtering to useI have tried something like this:
*[_type == 'hjelpeartikkel' && brodtekst[_type == 'hjelpeartikkel.expandCollapse'].innhold[_type == 'bilde'].marks[] != null]{ _id, brodtekst[_type == 'hjelpeartikkel.expandCollapse'] { innhold[_type == 'bilde'] { ... } } }
marks, I’ve also tried to
count(brodtekst[_type == 'hjelpeartikkel.expandCollapse'].innhold[_type == 'bilde'].marks[]) > 0
Apr 3, 2022, 7:26 AM
Hi User. I’m curious if this gets what you’re after:
*[_type == 'hjelpeartikkel' && brodtekst[_type == 'hjelpeartikkel.expandCollapse'].innhold[_type == 'bilde' && marks[] != null]]
Apr 3, 2022, 4:42 PM
O
hmm, no, can’t seem to get that to match any documents (and I know there is still at least one such document)
Apr 3, 2022, 4:51 PM
O
but I think
might have done it
*[_type == 'hjelpeartikkel' && count(brodtekst[_type == 'hjelpeartikkel.expandCollapse'].innhold[_type == 'bilde' && marks[] != null]) > 0]{ _id }
Apr 3, 2022, 4:53 PM
O
yeah it did, thanks for the help
user A
!Apr 3, 2022, 4:55 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.