mongodb - mongodb存储桶边界大于查询
问题描述
我有 mongodb 存储桶查询来获取下限和上限计数。现在我想要大于查询来显示 > 10%、> 20%、>50%、>60% 等的折扣。
我不知道如何包含大于边界。或使用任何其他方式来计算报价?
db.getCollection('product').aggregate([{$facet: {
"offers":[{$unwind:"$variants"},
{$match:{"variants.prices.discount_percent": { $exists: 1 },
"variants.is_published":{"$ne":false}}},
{
$bucket: {
groupBy: "$variants.prices.discount_percent",
boundaries: [ 0, 20, 30, 40, 100,Infinity ],
output: {
"count": { $sum: 1 }
}
} }
]}}
])
在这种情况下,我想要的是折扣总数。所以 20% 的折扣包括 30% 以上的折扣,30% 包括 40% 以上的折扣等等。
输出应该是:
20% - (10), 30% - (5), 40% - (2) 等等。
这里 20% 的计数是 10,其中也包括 5 和 2。因为它 >= 20。30% 包括 40% 的计数 2,因为它 >= 30。
解决方案
推荐阅读
- sql - 如何使用 REGEXP-SUBSTR
- ios - 快速从对象数组中删除某些对象
- c# - 如果在 UserControl 上使用 DataTemplate,WPF DependencyProperty OnPropertyChanged 将默认值返回为 NewValue
- apache-kafka - 提交偏移量时,kafka 流会超时
- php - 我已经使用 php 将 csv 导入到表中,但遇到了问题?
- amazon-web-services - 如何在不传递应用程序中的访问密钥和密钥的情况下访问 aws QLDB?
- java - 在 Spring Boot 应用程序中从 mongo db 获取数据,其中要获取的集合名称和字段在运行时是已知的
- c# - NHibernate 多对一映射
- android - 如何在改造标头android中传递String []?
- python-3.x - 如何将系列添加到数据框?