javascript Mongo Group Aggregate
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Mongo Group Aggregate相关的知识,希望对你有一定的参考价值。
//GROUP BY WORKSHOP ID
db.getCollection('enrolments').aggregate([{
$group:
{
_id: {workshopId: "$workshopId"},
contacts: { $push: {contactId: '$contactId'} }
}
}])
GROUP FIRST BY WEEKDAY AND WORKSHOP THEN BY WEEKDAY
db.getCollection('enrolments').aggregate([
{ $unwind: '$attendances' },
{
$group:
{
_id: {weekDay: "$attendances.weekDay", workshopId:"$workshopId"},
contacts: { $push: {contactId: '$contactId', day: "$attendances.day", status:'$attendances.status'} }
}
},
{
$group:
{
_id: {weekDay: "$_id.weekDay"},
workshops: { $push: {workshopId:'$_id.workshopId', contacts: '$contacts'} }
}
}
])
以上是关于javascript Mongo Group Aggregate的主要内容,如果未能解决你的问题,请参考以下文章
mongo分组统计(group)
Different AG groups have the exactly same group_id value if the group names are same and the ‘CLUSTE
Mongo每天汇总$group?
mongo14-----group???aggregate???mapReduce
mongo中的高级查询之聚合操作(distinct,count,group)与数据去重
mongo分组操作