本文介绍了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错误:“参数必须是聚合管道运算符"
发布评论