【问题标题】:How to write pipeline with group along with match?如何用组和匹配编写管道?
【发布时间】:2019-08-22 09:59:55
【问题描述】:

我使用 group 和 match 编写解析聚合管道,但它不起作用 它在 mongo compass 中工作,但在解析服务器中被拒绝,请建议正确的语法

test(callback) {
    let Employee = Parse.Object.extend("Employee");
    var query = new Parse.Query(Employee);
    var pipeline = [
        [
            {
                'match': {
                    'isActive': true
                } 
            }, {
                'group': {
                    'objectId': null, 
                    'total': {
                        '$sum': '$defaultAccNum'
                    }
                }
            }
        ]
    ]

    query.aggregate(pipeline, { useMasterKey: true })
        .then(function (results) {
            debugger
            // results contains sum of score field and stores it in results[0].total
          }).catch(function (error) {
            // There was an error.
          });
    }
}

【问题讨论】:

标签: javascript parse-server


【解决方案1】:

试试:

var pipeline = [
            {
                'match': {
                    'isActive': true
                } 
            }, {
                'group': {
                    'objectId': null, 
                    'total': {
                        '$sum': '$defaultAccNum'
                    }
                }
            }
    ]

【讨论】:

    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 2013-04-03
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    相关资源
    最近更新 更多