我有一个文档,它有一个对象数组,其中一个字段是对另一个文档的引用。下面的查询只返回引用的文档_id和_type,我需要这些文档中的其他字段。
// GROQ query
*[slug.current == $slug]{
title,
slug,
objectArray
}这导致:
"result": [
0: {
"title": "Test Document"
"slug": {
"_type": "slug"
"current": "test-document"
}
"objectArray": [
0: {...}
1: {
"_key": "583ec1dee738"
"_type": "documentObject"
"objectTitle" : "Test Object"
"documentReference": {
"_ref": "2f9b93b4-4924-45f2-af72-a38f7d9ebeb4"
"_type": "reference"
}
"booleanField": true
}
]
}
]documentReference有自己的一组字段(即。在需要在查询中返回的架构中。
我该怎么做?
发布于 2022-04-08 07:31:52
您需要对引用执行一个连接:
*[slug.current == $slug] {
title,
slug,
objectArray[] {
documentReference->
}
}语法objectArray[]可以被认为是“针对每个元素”,而->做了一个连接来查找引用的文档。在其他
https://stackoverflow.com/questions/71787329
复制相似问题