MongoDb 聚合 $match 错误:“参数必须是聚合管道运算符"; [英] MongoDb aggregation $match error : "Arguments must be aggregate pipeline operators"
本文介绍了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 错误:“参数必须是聚合管道运算符";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文