I have documents that look like this
{
"_type": "celeb",
"name": "foo",
"facts: [
{a: 1, topics: {_ref: 'asd', _type: 'reference'}},
{a: 2},
{a: 3, topics: {_ref: 'dfg', _type: 'reference'}}
]
}
Not all documents have facts
that have topics
. Some have facts
that don't have topics
. I'm trying to retrieve the ones that have it. I tried the following GROQ query
*[_type == 'celeb' && defined(facts[*].topics)]
The problem with the query above is that it doesn't discriminate between celebs
that have facts
which have objects containing topics
key, and celeb
that have facts
which do not have any objects containing topics
key.
How can I make the query return only celeb
documents that have facts
which have objects that have topics
defined?
defined(foo)
is just shorthand forfoo != null
, so that won't work. The solution is to count: