我有像这样的文件
{
"_type": "celeb",
"name": "foo",
"facts: [
{a: 1, topics: {_ref: 'asd', _type: 'reference'}},
{a: 2},
{a: 3, topics: {_ref: 'dfg', _type: 'reference'}}
]
}并不是所有的文档都有具有facts的topics。有些人有facts,但没有topics。我在试着找回那些有它的。我尝试了以下GROQ查询
*[_type == 'celeb' && defined(facts[*].topics)]上面的查询的问题是,它不区分具有包含celebs键的对象的facts和没有包含topics键的对象的facts的celeb。
如何使查询只返回具有定义了celeb对象的facts的facts文档?
发布于 2022-03-30 22:17:12
defined(foo)只是foo != null的缩写,所以这是行不通的。解决办法是计算:
*[_type == 'celeb' && count(facts[].topics) > 0]https://stackoverflow.com/questions/71683918
复制相似问题