diff --git a/src/monger/collection.clj b/src/monger/collection.clj index c085887..8dabfcf 100644 --- a/src/monger/collection.clj +++ b/src/monger/collection.clj @@ -68,9 +68,12 @@ ;; monger.collection/count (defn ^long count - [^String collection] - (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] - (.count coll))) + ([^String collection] + (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] + (.count coll))) + ([^String collection, ^Map conditions] + (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] + (.count coll (to-db-object conditions))))) ;; monger.collection/update ;; monger.collection/update-multi diff --git a/test/monger/test/collection.clj b/test/monger/test/collection.clj index af8e66b..0e32620 100644 --- a/test/monger/test/collection.clj +++ b/test/monger/test/collection.clj @@ -58,7 +58,18 @@ ;; (deftest get-collection-size - (is 0 (monger.collection/count "things"))) + (let [collection "things"] + (monger.collection/remove collection) + (is (= 0 (monger.collection/count collection))) + (monger.collection/insert collection { :language "Clojure", :name "monger" }) + (monger.collection/insert collection { :language "Clojure", :name "langohr" }) + (monger.collection/insert collection { :language "Clojure", :name "incanter" }) + (monger.collection/insert collection { :language "Scala", :name "akka" }) + (is (= 4 (monger.collection/count collection))) + (is (= 3 (monger.collection/count collection { :language "Clojure" }))) + (is (= 1 (monger.collection/count collection { :language "Scala" }))) + (is (= 0 (monger.collection/count collection { :language "Python" }))))) + (deftest remove-all-documents-from-collection (let [collection "libraries"]