[英]Filter within array in arangodb not working
I am trying to solve Q.20 on this page .我正在尝试解决此页面上的 Q.20。 The dataset is here
数据集在这里
Q20.Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those restaurants which achieved a score which is not more than 10. Q20.写一个 MongoDB 查询来查找那些得分不超过 10 的餐厅的餐厅 ID、名称、自治市镇和美食。
I am trying it the following way but I can see that I get results of restaurants with scores of [2,6,10,9,14] and [8,23,12,12].我正在尝试以下方式,但我可以看到我得到的餐馆结果得分为 [2,6,10,9,14] 和 [8,23,12,12]。 So I know it can't be right.
所以我知道这不可能。
for r in restaraunts
for g in r.grades
filter g.score <=10
return distinct {ID:r.restaurant_id,name:r.name,borough:r.borough,cuisine:r.cuisine,score:r.grades[*].score}
Please help, I have tried different projections of the scores, but I feel I'm overlooking something.请帮忙,我尝试过不同的分数预测,但我觉得我忽略了一些东西。 If I use collect I still get it wrong
如果我使用 collect 我仍然会出错
collect rest=r.restaurant_id,name= r.name, bor=r.borough,cuis=r.cuisine, sc=r.grades[*].score into groups
for g in sc
filter g<=10
return {rest:rest,name:name,bor:bor,cuis:cuis,sc:g}
Use the MAX()
function to determin the value to be filtered:使用
MAX()
function 确定要过滤的值:
for r in restaurants
LET score = MAX(r.grades[*].score)
filter score <=10
return distinct {ID:r.restaurant_id,name:r.name,borough:r.borough,cuisine:r.cuisine,score:score}
I didn't test this against your dataset, but with this small snippet:我没有针对您的数据集进行测试,但是使用了这个小片段:
LET r = {'grades': [ {score: 5}, {score: 7}, {score: 15} ] }
RETURN MAX(r.grades[*].score)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.