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

编程入门 行业动态 更新时间:2024-10-24 09:26:00
本文介绍了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

我错过了什么?

推荐答案

Pipeline stage 是数组中单独的 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:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管道   运算符   错误   参数   MongoDb

发布评论

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

>www.elefans.com

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