英文:
How to create a key value pairs of couchbase document using couchbase query
问题
以下是您的翻译:
问题描述:
我正在为我的项目编写Couchbase查询,遇到了一个查询的问题。以下是问题的详细信息。
我有一个名为“workflow”的桶,里面有一些文档:
{
type = "task",
status = "Completed",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 1
},
{
type = "task",
status = "Completed",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 2
},
{
type = "task",
status = "New",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 3
},
{
type = "task",
status = "New",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 4
},
{
type = "task",
status = "New",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 5
}
我编写了以下查询:
select status, count(*) from workflow where type="task" and appId="72689c67-f5d1-474a-8802-77f332144b12" and status!="" group by status;
结果:
[
{
"$1": 2,
"status": "Completed"
},
{
"$1": 3,
"status": "New"
}
]
期望结果:
[
{
"Completed": 2
},
{
"New": 3
}
]
是否有一种方法可以获得期望的结果?任何线索都将非常有帮助。这将使我免于运行不必要的for循环,从而在扩展时优化我的代码。还有没有其他方法替代以下语句?
status!=""
英文:
I am writing couchbase query for my project and facing problem in 1 query. Below is the details of the problem.
I have a bucket name as "workflow" and I have few documents in it :-
{
type = "task",
status = "Completed",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 1
},
{
type = "task",
status = "Completed",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 2
},
{
type = "task",
status = "New",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 3
},
{
type = "task",
status = "New",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 4
},
{
type = "task",
status = "New",
appId = "72689c67-f5d1-474a-8802-77f332144b12",
taskNo = 5
}
I have written a query :-
select status, count(*) from workflow where type="task" and appId="72689c67-f5d1-474a-8802-77f332144b12" and status!="" group by status;
Result :-
[
{
"$1": 2,
"status": "Completed"
},
{
"$1": 3,
"status": "New"
}
]
Expected Result :-
[
{
"Completed": 2
},
{
"New": 3
}
]
Is there a way that we can get the expected result? Any leads will be really very helpful. I will be saved from running unnecessary for loop which will optimise my code during scaling. And any other alternative for the below statement?
status!=""
答案1
得分: 2
select RAW {status:count(1)}
from workflow
where type="task"
and appId="72689c67-f5d1-474a-8802-77f332144b12"
and status != ""
group by status;
OR
SELECT RAW OBJECT v.status:v.cnt
FOR v IN (select status, count(1) AS cnt
from workflow
where type="task"
and appId="72689c67-f5d1-474a-8802-77f332144b12"
and status != ""
group by status)
END;
You can use status > "" AND status < []
英文:
select RAW {status:count(1)}
from workflow
where type="task"
and appId="72689c67-f5d1-474a-8802-77f332144b12"
and status != ""
group by status;
OR
SELECT RAW OBJECT v.status:v.cnt
FOR v IN (select status, count(1) AS cnt
from workflow
where type="task"
and appId="72689c67-f5d1-474a-8802-77f332144b12"
and status != ""
group by status)
END;
You can use status > "" AND status < []
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论