我有一个文档,其中包含一组对象,其中一个字段是对另一个文档的引用。以下查询仅返回引用的文档 _id 和 _type,我需要这些文档中的其他字段。
// GROQ query
*[slug.current == $slug]{
title,
slug,
objectArray
}
Run Code Online (Sandbox Code Playgroud)
这导致:
"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
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
documentReference
在模式中有自己的一组字段(即标题),我需要在查询中返回这些字段。
我该怎么做呢?
您需要对引用进行连接:
\n*[slug.current == $slug] {\n title,\n slug,\n objectArray[] {\n documentReference->\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n语法objectArray[]
\xc2\xa0 可以被认为是“对于每个元素”,并->
执行连接来查找引用的文档。其他
归档时间: |
|
查看次数: |
4002 次 |
最近记录: |