Mongodb中几种聚合查询组合的案例
2017-07-14 08:50
579 查看
db.onePager2ReadHistory.aggregate([ {$match: {'userId': '55054a56ad274f0b473fad39', 'isDeleted': 0}}, {$unwind: '$articleTags'}, { $group: { '_id': {'tagName': '$userId'}, 'firstTimeReadingPoints': { $sum: { $cond: [ '$isLongTimeReading', 4, { $cond: [ {$gt: ['$readCount', 0]}, 3, 0 ] } ] } }, 'praisePoints': { $sum: { $cond: [ {$eq: ['$like', 1]}, 3, 0 ] } }, 'repeatReadingPoints': { $sum: { $cond: [ {$gt: ['$readCount', 1]}, { $multiply: [ 6, { $subtract: ['$readCount', 1] } ] }, 0 ] } } } }, { $project: { '_id': 0, 'tagName': '$_id.tagName', 'firstTimeReadingPoints': 1, 'praisePoints': 1, 'repeatReadingPoints': 1, 'weight': { $divide: [ {$add: ['$firstTimeReadingPoints', '$praisePoints', '$repeatReadingPoints']}, 10 ] } } } ])
相关文章推荐
- JAVA mongodb 聚合几种查询方式详解
- MongoDB高级查询[聚合Group]
- MongoDB 高级聚合查询
- UML中类之间的几种关系,关联(association),聚合(Aggregation),组合(Composition)
- 在SPRING DATA MONGODB中使用聚合统计查询
- MongoDB涉及的业务比较慢--慢查询优化分析案例--以及参数说明
- UML中的几种关系——依赖、关联、聚合、组合、泛化、实现
- MongoDB高级查询[聚合Group]
- mongodb nodeJs聚合查询
- python操作mongodb之二聚合查询
- 类与类之间的几种关系(继承、实现、依赖、关联、聚合、组合)
- Step into MongoDB - 08 - 聚合查询
- MongoDB简单查询操作符(非聚合操作)
- MongoDB高级查询[聚合Group]
- UML类图几种关系的总结(泛化 、继承、实现、依赖、关联、聚合、组合)
- MongoDB学习--高级查询 [聚合Group]
- MongoDB 多条件组合查询
- MongoDB聚合查询
- MongoDB 聚合查询
- UML类图几种关系的总结,泛化 = 实现 > 组合 > 聚合 > 关联 > 依赖