-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdraft.rb
44 lines (40 loc) · 1.04 KB
/
draft.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# db.zipcodes.aggregate( [
# { $group:
# {
# _id: { state: "$state", city: "$city" },
# pop: { $sum: "$pop" }
# }
# },
# { $sort: { pop: 1 } },
# { $group:
# {
# _id : "$_id.state",
# biggestCity: { $last: "$_id.city" },
# biggestPop: { $last: "$pop" },
# smallestCit y: { $first: "$_id.city" },
# smallestPop: { $first: "$pop" }
# }
# }
# )
# group(by: [:state, :city], pop: sum(:pop)),
# sort(by: { pop: ASC }),
# group( by: :_id['state'],
# biggestCity: last(:_id['city']),
# biggestPop: first(:pop),
# smallestCity: last(:_id['city']),
# smallestPop: first(:pop))
# # Example of use
# generate_aggregation(
# group_by([:state, :city]) do
# { pop: sum(:pop) }
# end,
# sort_by(pop: 1),
# group_by("_id.state") do
# {
# biggestCity: last("_id.city"),
# biggestPop: last("pop"),
# smallestCity: first("_id.city"),
# smallestPop: first("pop")
# }
# end
# )