diff --git a/src/clojure/monger/operators.clj b/src/clojure/monger/operators.clj index 5cdd24b..8fd13ec 100644 --- a/src/clojure/monger/operators.clj +++ b/src/clojure/monger/operators.clj @@ -210,6 +210,9 @@ (defoperator $avg) (defoperator $sum) +(defoperator $first) +(defoperator $last) + (defoperator $add) (defoperator $divide) (defoperator $multiply) diff --git a/test/monger/test/aggregation_framework_test.clj b/test/monger/test/aggregation_framework_test.clj index 7af2f2f..e3d2aba 100644 --- a/test/monger/test/aggregation_framework_test.clj +++ b/test/monger/test/aggregation_framework_test.clj @@ -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)))))