关于mongodb的aggregate问题,求解答
2015-10-04 · 知道合伙人软件行家
Axure夜话
知道合伙人软件行家
向TA提问 私信TA
知道合伙人软件行家
采纳数:1197
获赞数:1344
1992年毕业于太原理工大学,20年IT公司工作经验现任山西誉海和科技有限公司技术总监,老二牛车教育课程总监
向TA提问 私信TA
关注
展开全部
aggregate是monogodb的聚合函数。完成类似于sql中的sum,count,group by等相关操作
1:count(*)
/**
* select count(*) count from zipsController
*/
var pipeline = [
{
$group: {
_id: null,
count: {$sum: 1}
}
}
];
2:sum(*)
/**
* select sum(pop) total from zipsController
*/
var pipeline = [
{
$group: {
_id: null,
total: {$sum: "$pop"}
}
}
];
3:group by
/**
* select sum(pop) total from zipsController group by state
*/
var pipeline =[
{
$group: {
_id: "$state",
totalpop: {$sum: "$pop"}
}
}
];
1:count(*)
/**
* select count(*) count from zipsController
*/
var pipeline = [
{
$group: {
_id: null,
count: {$sum: 1}
}
}
];
2:sum(*)
/**
* select sum(pop) total from zipsController
*/
var pipeline = [
{
$group: {
_id: null,
total: {$sum: "$pop"}
}
}
];
3:group by
/**
* select sum(pop) total from zipsController group by state
*/
var pipeline =[
{
$group: {
_id: "$state",
totalpop: {$sum: "$pop"}
}
}
];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询