Mongodb是用Sum 和Where条件

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; } } );

  

 

posted @ 2016-12-29 18:09  iDEAAM  阅读(8781)  评论(0编辑  收藏  举报