草庐IT

purchasequantity

全部标签

mongodb - 如何获取聚合的前 n 个存储桶,以及将所有其他存储桶组合成 "other"存储桶?

假设一个集合的模式如下所示:{"customer":,"purchase":,}现在,我想获得前5位客户(按购买数量),第6个桶是“其他”,它结合了其他客户的所有购买数量。基本上,聚合的输出应该是这样的:{"_id":"customer100","purchasequantity":4000000}{"_id":"customer5","purchasequantity":81800}{"_id":"customer4","purchasequantity":40900}{"_id":"customer3","purchasequantity":440}{"_id":"customer

mongodb - 如何获取聚合的前 n 个存储桶,以及将所有其他存储桶组合成 "other"存储桶?

假设一个集合的模式如下所示:{"customer":,"purchase":,}现在,我想获得前5位客户(按购买数量),第6个桶是“其他”,它结合了其他客户的所有购买数量。基本上,聚合的输出应该是这样的:{"_id":"customer100","purchasequantity":4000000}{"_id":"customer5","purchasequantity":81800}{"_id":"customer4","purchasequantity":40900}{"_id":"customer3","purchasequantity":440}{"_id":"customer