We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eb96f66 commit 5ba63b6Copy full SHA for 5ba63b6
examples/aggregate.rb
@@ -0,0 +1,25 @@
1
+# Group documents by field and calculate count.
2
+
3
+coll = client[:restaurants]
4
5
+results = coll.find.aggregate([ { '$group' => { '_id' => '$borough',
6
+ 'count' => { '$sum' => 1 }
7
+ }
8
9
+ ])
10
11
+results.each do |result|
12
+ puts result
13
+end
14
15
+# Filter and group documents
16
17
+results = coll.find.aggregate([ { '$match' => { 'borough' => 'Queens',
18
+ 'cuisine' => 'Brazilian' } },
19
+ { '$group' => { '_id' => '$address.zipcode',
20
+ 'count' => { '$sum' => 1 } } }
21
22
23
24
25
0 commit comments