I can get all stats of the site with aggregation
but I want to it for a certain user, like $where
.
我可以通过聚合获取网站的所有统计信息,但我想为某个用户提供它,例如$ where。
All stats:
games.aggregate([{
$group: {
_id: '$id',
game_total: { $sum: '$game_amount'},
game_total_profit: { $sum: '$game_profit'}}
}]).exec(function ( e, d ) {
console.log( d )
})
When I try to use $match
operator, I'm getting error :
当我尝试使用$ match运算符时,我收到错误:
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
What am I missing?
我错过了什么?
1 个解决方案
#1
17
Pipeline stages are separate BSON documents in the array:
管道阶段是阵列中单独的BSON文档:
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 )
});
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.
所以JavaScript中的数组或[]括号表示它需要提供“列表”。这意味着“文档”列表,这些文档通常以带有{}括号的JSON表示法指定。
#1
17
Pipeline stages are separate BSON documents in the array:
管道阶段是阵列中单独的BSON文档:
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 )
});
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.
所以JavaScript中的数组或[]括号表示它需要提供“列表”。这意味着“文档”列表,这些文档通常以带有{}括号的JSON表示法指定。