Skip to content

Instantly share code, notes, and snippets.

@anicet
Created March 20, 2015 08:08
Show Gist options
  • Save anicet/47bf383a554a76eb7e1c to your computer and use it in GitHub Desktop.
Save anicet/47bf383a554a76eb7e1c to your computer and use it in GitHub Desktop.
Mongoid map reduce find duplicate email
map = %Q{function() { emit(this.email, 1); }}
reduce = %Q{function(k, v) {return Array.sum(v);}}
User.all.map_reduce(map, reduce).out(inline: true).map{|u|
u["_id"] if u["value"] != 1.0
}.compact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment