【发布时间】:2020-02-12 05:37:46
【问题描述】:
我有这样的文件:
文件:
{score: 1, value: 10}
{score: 3, value: 10}
{score: 1, value: 10}
{score: 4, value: 10}
{score: 1, value: 10}
{score: 5, value: 10}
{score: 5, value: 10}
{score: 10, value: 10}
在这个集合中,没有 2、6、7、8、9 的分数,但我需要如下输出。
输出:
{score: 1, avg: 10}
{score: 2, avg: 0}
{score: 3, avg: 10}
{score: 4, avg: 10}
{score: 5, avg: 10}
{score: 6, avg: 0}
{score: 7, avg: 0}
{score: 8, avg: 0}
{score: 9, avg: 0}
{score: 10, avg: 10}
Mongo 聚合中的任何选项都会生成这个。请帮忙
【问题讨论】:
-
你怎么知道没有分数:2,6,7,8,9。您是否事先知道
score的项目范围从 1 到 10? -
你的 mongo 版本是什么?
标签: mongodb mongodb-query aggregation-framework