求大神讲解一下如何mongo如何多维度聚合
就比如我现在有一个表里面有:
{school :1 ,class :1 ,student :20},
{school :1 ,class :2 ,student :30},
{school :2,class :1 ,student :20},
{school :2 ,class :2 ,student :30},
我希望查询后 就变成
-----------------------------------------------------------------------------------------------------------------------
{
school :1
class : {
1:{
student :20
}
2:{
student :30
}
}
}
{
school :2
class : {
1:{
student :20
}
2:{
student :30
}
}
}
-----------------------------------------------------------------------------------------------------------------
刚入门 mongo 求大神讲解。