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

  

 

原文地址:https://www.cnblogs.com/haoliansheng/p/6234009.html