mongodb 删除重复的数据
作者:互联网
//PlaceName:'$PlaceName',CityCode:'$CityCode' 查询条件
//dups 查询到的重复数据
db.getCollection('HotLocation').aggregate([
{
$group:{_id:{PlaceName:'$PlaceName',CityCode:'$CityCode'},count:{$sum:1},dups:{$addToSet:'$_id'}}
},
{
$match:{count:{$gt:1}}
}
]).forEach(function(it){
//it.dups.shift(); 保留重复的第一条 避免全部删除了
it.dups.shift();
db.getCollection("HotLocation").remove({_id: {$in: it.dups}});
});
标签:PlaceName,CityCode,删除,dups,重复,mongodb,getCollection,HotLocation,id 来源: https://www.cnblogs.com/llsade/p/14846128.html