时间:2021-07-01 10:21:17 帮助过:13人阅读
db.集合名称.aggregate([{管道:{表达式}}])
ps ajx | grep mongo
表达式:‘$列名‘
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
counter:{$sum:1}
}
}
])
db.stu.aggregate([
{$group:
{
_id:null,
counter:{$sum:1},
avgAge:{$avg:‘$age‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
name:{$push:‘$name‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
name:{$push:‘$$ROOT‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
counter:{$sum:1}
}
}
])
db.stu.aggregate([
{$group:
{
_id:null,
counter:{$sum:1},
avgAge:{$avg:‘$age‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
name:{$push:‘$name‘}
}
}
])
db.stu.aggregate([
{$group:
{
_id:‘$gender‘,
name:{$push:‘$$ROOT‘}
}
}
])
mongodb 高级操作
标签:数组 命令 limit mongodb 管道 拆分 组类型 counter 姓名