MongoDb聚合$ match错误:“参数必须是聚合管道运算符" [英] MongoDb aggregation $match error : "Arguments must be aggregate pipeline operators"

查看:370
本文介绍了MongoDb聚合$ match错误:“参数必须是聚合管道运算符"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用aggregation来获取该网站的所有统计信息,但我想为某个用户(例如$where)获得它.

I can get all stats of the site with aggregation but I want to it for a certain user, like $where.

所有统计信息:

games.aggregate([{
                $group: {
                    _id: '$id',
                    game_total: { $sum: '$game_amount'}, 
                    game_total_profit: { $sum: '$game_profit'}}
                }]).exec(function ( e, d ) {

                    console.log( d )            

            })

当我尝试使用$match运算符时,出现错误:

When I try to use $match operator, I'm getting error :

games.aggregate([{
                $match: { '$game_user_id' : '12345789' },
                $group: {
                    _id: '$id',
                    game_total: { $sum: '$game_amount'}, 
                    game_total_profit: { $sum: '$game_profit'}}
                }]).exec(function ( e, d ) {

                    console.log( d )            

            })

Arguments must be aggregate pipeline operators

我想念什么?

推荐答案

管道阶段是数组中单独的BSON文档:

Pipeline stages are separate BSON documents in the array:

games.aggregate([
                { $match: { 'game_user_id' : '12345789' } },
                { $group: {
                    _id: '$id',
                    game_total: { $sum: '$game_amount'}, 
                    game_total_profit: { $sum: '$game_profit'}}
                }}
]).exec(function ( e, d ) {
    console.log( d )            
});

因此,JavaScript中的Array或[]括号表示这意味着它希望提供列表".这意味着通常以{}大括号在JSON表示法中指定的文档"列表.

So the Array or [] bracket notation in JavaScript means it expects a "list" to be provided. This means a list of "documents" which are generally specified in JSON notation with {} braces.

这篇关于MongoDb聚合$ match错误:“参数必须是聚合管道运算符"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆