kingschan1204 / blog

个人技术blog
https://github.com/kingschan1204/blog/issues
1 stars 1 forks source link

mongodb 多字段group by #30

Open kingschan1204 opened 5 years ago

kingschan1204 commented 5 years ago
db.task.group( {
     key: { PotNo: true,jhrw_rwlx:true},   //字段
     initial: {count: 0},
     reduce: function(obj,prev){ prev.count++;},
     } )

后者直接写jsoncommand

 Document doc=  mongoTemplate.executeCommand("{'group' : {'ns' : 'task','key' : {'PotNo': true,'jhrw_rwlx':true},'initial' : {'count' : 0},'$reduce' : 'function(doc,prev){prev.count++;}'}}");