Last active
January 11, 2016 22:01
-
-
Save sadhu89/12fd5d519411089d5387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devices=Customer.collection.aggregate([ | |
{ | |
"$group" => { | |
_id: "$device_id", | |
count:{"$sum"=>1} | |
} | |
}, | |
{ | |
"$match"=>{ | |
count:{"$gte"=>3} | |
} | |
}, | |
{ | |
"$sort"=>{ | |
count:-1 | |
} | |
} | |
]) | |
report=[] | |
devices.each do |d| | |
Customer.where(device_id: d["_id"]).each do |c| | |
report<<"#{c.name}, #{c.email}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment