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