96dp8g
Last Updated: February 25, 2016
·
1.319K
· solojavier
Screen shot 2014 07 16 at 1.31.56 pm

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
Say Thanks
Respond