Added support for $first and $last aggregation operators.

This commit is contained in:
Matti Jagula 2013-12-04 21:43:40 +02:00
parent 568ba283c8
commit c81026e308
2 changed files with 22 additions and 0 deletions

View file

@ -210,6 +210,9 @@
(defoperator $avg) (defoperator $avg)
(defoperator $sum) (defoperator $sum)
(defoperator $first)
(defoperator $last)
(defoperator $add) (defoperator $add)
(defoperator $divide) (defoperator $divide)
(defoperator $multiply) (defoperator $multiply)

View file

@ -67,3 +67,22 @@
{$group {:_id "$state" {$group {:_id "$state"
:total {$sum "$subtotal"}}}]))] :total {$sum "$subtotal"}}}]))]
(is (= expected result))))) (is (= expected result)))))
(deftest test-$first-aggregation-operator
(let [collection "docs"
batch [{ :state "CA" }
{ :state "IL"}]
expected "CA"]
(mc/insert-batch collection batch)
(let [result (:state (first (mc/aggregate collection [{$group { :_id 1 :state {$first "$state"} }}])))]
(is (= expected result)))))
(deftest test-$last-aggregation-operator
(let [collection "docs"
batch [{ :state "CA" }
{ :state "IL"}]
expected "IL"]
(mc/insert-batch collection batch)
(let [result (:state (first (mc/aggregate collection [{$group { :_id 1 :state {$last "$state"} }}])))]
(is (= expected result)))))