【问题标题】:MongoDB aggregate assert: command failedMongoDB聚合断言:命令失败
【发布时间】:2017-08-25 16:23:14
【问题描述】:

我使用此查询来查找状态(“isActive”:false)true or false还根据状态最后计数总金额查找年龄

db.programmershelper.aggregate([{
    $match: {
        "isActive": false
    }
}, {
    $group: {
        _id: "age",
        total: { $count: "$amount" } 
    }
}])

同时显示此消息 断言:命令失败:{ “好”:0, "errmsg" : "未知组运算符 '$count'", “代码”:15952, “代号”:“位置 15952” }

跟随错误

聚合失败
_getErrorWithCode@src/mongo/shell/utils.js:25:13

【问题讨论】:

  • 这里的age 是什么?什么是“金额”?

标签: mongodb aggregation


【解决方案1】:

您可以关注count, sum and average docs for group,根据您的要求找到确切的解决方案。

至于我从问题中了解到的,您想根据过滤器"isActive": false 进行聚合,并根据最后的总数查找年龄。

db.programmershelper.aggregate([{
    $match: {
        "isActive": false
    }
}, {
    $group: {
        _id: "age",
        count: { $sum: 1 }
    }
}])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多