我想分組統(tǒng)計數(shù)組,然后條件是時間區(qū)域,怎么實現(xiàn)// 報錯信息// [Error] A pipeline stage specification object must contain exactly one field. at line 1, column 1db.getCollection("user_reg").aggregate([
{ "$group": {
_id: "$isfrom",
count: { "$sum": 1
},
}, "$match": { "regtime": { "$gte": '2000-01-01', "$lte": '2020-01-01'
}
}
}
])
2 回答

慕田峪4524236
TA貢獻1875條經(jīng)驗 獲得超5個贊
不知道原始數(shù)據(jù)是什么樣,不過通常來講應該先過濾再分組。同時一個數(shù)組元素里面只應該有一個運算符($match/$group等):
db.getCollection("user_reg").aggregate([ { "$match": { "regtime": { "$gte": '2000-01-01', "$lte": '2020-01-01' } } }, { "$group": { _id: "$isfrom", count: { "$sum": 1 }, } } ])
- 2 回答
- 0 關注
- 4440 瀏覽
添加回答
舉報
0/150
提交
取消