I have a data in MongoDB and I want to remove all the duplicated Documents. The problem is MongoDB assigns each item a unique _id
so I can't just delete the duplicated items. I have a field in each Document called name
and I want to delete the items that have the same name
.
For example:
[{_id: 5c7e423f0bdaa9aeb5399e90,
name ="A"
grade = 16
enrolled ="dddh"
},
{_id: 5c7e423f1bdaa9aeb5399e90,
key ="B"
grade =17
note ="ddddd"
},
{_id: 5c7e423d0bdaa9aeb5399e90,
key ="B"
score =17
note ="ddddd"
}]
to:
[{_id: 5c7e423f0bdaa9aeb5399e90,
name ="A"
grade = 16
enrolled ="dddh"
},
{_id: 5c7e423f1bdaa9aeb5399e90,
name ="B"
grade =17
enrolled ="ddddd"
}]
The list might be big so is there any efficient way to do it?