Merge pull request #65 from mlni/add_first_and_last_operators

Added support for $first and $last aggregation operators.
This commit is contained in:
Michael Klishin 2013-12-04 12:05:26 -08:00
commit 3083a18191
2 changed files with 22 additions and 0 deletions

View file

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

View file

@ -67,3 +67,22 @@
{$group {:_id "$state"
:total {$sum "$subtotal"}}}]))]
(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)))))