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

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM