首页 > 数据库技术 > 详细

Mongodb是用Sum 和Where条件

时间:2016-12-29 20:16:55      阅读:419      评论:0      收藏:0      [点我收藏+]

Sum

按照条件求和

db.aa.aggregate([
                     
                     { $group: { _id: null, total: { $sum: "$value" } } }, //$value 指的是按照那一列来sum。比如 value是mongo的一列。那么此处应该是 $value
                     { $sort: { total: -1 } }
                   ])

 

 

Where条件

db.myCollection.find( { $where: "this.credits == this.debits" } );
db.myCollection.find( { $where: "obj.credits == obj.debits" } );

db.myCollection.find( { $where: function() { return (this.credits == this.debits) } } );
db.myCollection.find( { $where: function() { return obj.credits == obj.debits; } } );

  

 

Mongodb是用Sum 和Where条件

原文:http://www.cnblogs.com/haoliansheng/p/6234009.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!