Can anyone please share an example of proper use of the MongoDB::Collection aggregate function in Perl? I am looking to do a simple sum of a field where another field equals some value x.
From there I'll be able to figure out the rest.
Thanks
Here is an example which I've built.
for (my $i=0; $i<100; $i++) {
my $number = $i*100;
my $result = $collection->aggregate([{"\$match" => {"b" => {"\$gte" => $number, "\$lt" => $number+1000}}}, {"\$group" => {"_id" => 0, "average" => {"\$avg" => "\$b"}, "count" => {"\$sum" => 1}}}]);
print Dumper($result);
}
You can find more information at http://docs.mongodb.org/manual/aggregation/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With