mongodb 实现 group having

mongdo 实现批量删除。
var group =
 {
     "$group":{
         "_id":{"uid":"$uid"},
         "count":{"$sum" : 1}
     }
 
 };


  var match =
{
     "$match":{
         "count" : {
             "$gt" : 1
         }
     }
 }

var course = db.baidu2.aggregate(group, match);
  while(course.hasNext()){
      var keeper = course.next();
      
      var query = {"uid":keeper._id.uid};
      var res = db.baidu2.find(query).skip(1);
  
      while(res.hasNext()){
         var row = res.next();
         if(row.city != undefined) {
             db.baidu2.remove({"_id" : row._id});
         }
     }
 }

你可能感兴趣的:(mongodb 实现 group having)