【发布时间】:2021-12-25 21:47:29
【问题描述】:
我正在尝试查找数组字段的总和,然后,想要过滤这些总和大于 100。
{
name: 'John',
grades: [60, 70, 40] # sum of this array = 170 (take this)
},
{
name: 'Doe',
grades: [30, 20, 10] # sum of this array = 60 (don't take this)
}
我对这个集合做了这样的投影:
db.collections.find({}, {
{
sumOfGrades: { $sum: "$grades" }
})
// returns
{...sumOfGrades: 170}, {...sumOfGrades: 60}
// But I am trying to get the first doc(which is greater than 100) on mongoDB layer.
【问题讨论】:
标签: mongodb mongodb-query