Last Updated: February 25, 2016
·
2.054K
· solojavier

Find duplicate documents in mongoid with map/reduce

map = %Q{
  function() {
     emit(this.email, 1);
  }
}

reduce = %Q{
  function(key, values) {
    return Array.sum(values);
  }
}

User.all.map_reduce(map, reduce).out(inline: true).each do |u|
  p u["_id"] if u["value"] != 1
end