MongoDB: find duplicates in a field
This little script helps find duplicated data in a MongoDB field.
m = function () {
emit(this.my_field, 1);
}
r = function (k, vals) {
return Array.sum(vals);
}
res = db.MyCollection.mapReduce(m,r, { out : "my_output" });
db[res.result].find({value: {$gt: 1}});
Written by Franklin Dattein
Related protips
1 Response
db.MyCollection.aggregate([
{$group : { id: "$myfield" , count : { $sum: 1}}},
{$match : { count : { $gt : 1 } }} ])
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mongodb
Authors
Related Tags
#mongodb
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#