您的位置:首页 > 博客中心 > 数据库 >

mongodb删除某字段重复的操作

时间:2022-03-15 18:32

db.info.aggregate([
{
$group:{_id:{Matchid:"$Matchid"},count:{$sum:1},dups:{$addToSet:"$_id"}}
},
{
$match:{count:{$gt:1}}
}

]).forEach(function(doc){
doc.dups.shift();
db.info.remove({_id:{$in:doc.dups}});
})

热门排行

今日推荐

热门手游