【发布时间】:2021-04-19 00:50:00
【问题描述】:
我正在尝试解决this page 上的 Q.20。数据集为here
Q20.编写一个 MongoDB 查询来查找得分不超过 10 的餐厅的餐厅 ID、名称、行政区和美食。
我正在尝试以下方式,但我可以看到我得到的餐馆的结果是 [2,6,10,9,14] 和 [8,23,12,12]。所以我知道这不可能。
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}
请帮忙,我尝试了不同的分数预测,但我觉得我忽略了一些东西。如果我使用 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}
【问题讨论】: