我有下面的 couchbase 文档,
{
"appId": "f1606a90-c96f-4db9-8e5f-9f0b6d2d2106",
"attributes": [
{
"label": "Reviewed By",
"name": "reviewedBy",
"value": "QA.Praveen"
},
{
"label": "Assigned To",
"name": "assignedTo",
"value": "Praveen"
},
{
"label": "Completed Lines",
"name": "completedLines",
"value": "23"
}
],
"hasConversations": false,
"id": "02efdb67-798f-4616-9750-c80c17c4c1ee",
"status": "Completed",
"task": {
"details": {
"hasAttachments": true,
"importance": "normal",
"subject": "very interesting"
},
"taskType": "mail"
},
"taskId": "02efdb67-798f-4616-9750-c80c17c4c1ee",
"type": "task"
}
找到一个查询,我们可以从中获取展平文档而不是嵌套数组对象 我试过以下查询,
SELECT a.taskId, a.appId, ARRAY_FLATTEN( ARRAY_AGG ({ attr.name:attr.`value`}) ,0) as attr FROM workFlowDetails a UNNEST a.attributes attr WHERE a.type = "task" and a.taskId = '02efdb67-798f-4616-9750-c80c17c4c1ee' GROUP BY a.taskId, a.appId;
但是这个查询没有按要求工作,
预期输出为:
{
"appId": "f1606a90-c96f-4db9-8e5f-9f0b6d2d2106",
"taskId": "02efdb67-798f-4616-9750-c80c17c4c1ee",
"type": "task",
"hasConversations": false,
"id": "02efdb67-798f-4616-9750-c80c17c4c1ee",
"status": "Completed",
"reviewedBy": "QA.Praveen",
"assignedTo": "Praveen",
"completedLines": "23",
"taskType": "mail",
"hasAttachments": true,
"importance": "normal",
"subject": "very interesting"
}