MongoDb聚合$ match错误:“参数必须是聚合管道运算符"

编程入门 行业动态 更新时间:2024-10-24 07:34:26
本文介绍了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错误:“参数必须是聚合管道运算符"

本文发布于:2023-11-22 13:15:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管道   运算符   错误   参数   MongoDb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!