Mongodb Aggregate,MapReduce Sample
来源:互联网 发布:在线制作淘宝商品图片 编辑:程序博客网 时间:2024/05/26 02:55
数据格式:
{
"_id" : 1,"durationId" : 201505181130,
"feeds" : {
"9" : {
"CommentUserIds" : [
3
],
"CreateTime" : "201503282000",
"WeightPerDuration" : 713.7724609375
},
"10" : {
"LikeUserIds" : [
4
],
"CreateTime" : "201503281930",
"WeightPerDuration" : 713.7719116210938
}
}
}
{
"_id" : 2,"durationId" : 201505181200,
"feeds" : {
"9" : {
"CommentUserIds" : [
3
],
"CreateTime" : "201503282000",
"WeightPerDuration" : 713.7724609375
},
"10" : {
"LikeUserIds" : [
4
],
"CreateTime" : "201503281930",
"WeightPerDuration" : 713.7719116210938
}
}
}
Aggregate feedId为9的数组去重相加:
db.feed.aggregate( {$match:{"durationId":{$gt:1}} ,{$project: {commentWeight: { $size:{$ifNull: ["$feeds.9.CommentUserIds",[]]} }, likeWeight: { $size:{$ifNull: ["$feeds.9.LikeUserIds",[]]} }, shareWeight: { $size:{$ifNull: ["$feeds.9.ShareUserIds",[]]} }, viewWeight: { $size:{$ifNull: ["$feeds.9.ViewUserIds",[]]} }, detailWeight: { $size:{$ifNull: ["$feeds.9.DetailUserIds",[]]} }} })
MapReduce 根据feedId分组,求WeightPerDuration和:
mr = db.runCommand({
"mapreduce" : "feed",
"map" : function() {
for (var key in this.feeds) {
emit(key, this.feeds[key].WeightPerDuration);
}
},
"reduce" : function(key, values) { return Array.sum(values); },
"query" : { durationId : {$gte:1}, durationId : {$lte:1} },
"out": "feed" + "_keys"
})
- Mongodb Aggregate,MapReduce Sample
- MongoDB中group() mapReduce() aggregate()之比较
- mongodb mapreduce, aggregate, group 的类似功能
- MongoDB aggregate,mapreduce,聚合命令的区别
- mongodb aggregate 级联查询
- Mongodb aggregate timezone 问题
- mongodb aggregate 聚合操作
- mongodb的aggregate 用法
- java mongodb aggregate用法
- Mongodb——Aggregate
- MongoDB aggregate聚合
- MongoDB aggregate 聚合管道
- mongodb 聚合aggregate 乘法
- MongoDB中的聚合 aggregate
- java mongodb aggregate用法
- golang mongodb Aggregate
- MongoDB aggregate() 聚合
- java mongodb aggregate用法
- 第十一周项目四 类族的设计(2)
- leetcode Add Two Numbers
- c#打开对话框选择后输出文件路径文件名
- MySQL中SYSDATE()和NOW()的区别
- iOS开发:导入字体库
- Mongodb Aggregate,MapReduce Sample
- C++去除字符串中存在的空格
- 黑马程序员——开发工具——Eclipse
- PHP笔记-自动加载函数库与扩展函数库定义及模板显示与模板替换地址
- 利用jquery.zclip在浏览器里复制内容到剪切板
- POJ 1051 P,MTHBGWB
- 开始刷leetcode day15:Valid Parentheses
- java.lang.Class类详解
- ssdb get的设计问题