Add monger.collection/count version that takes conditions argument

This commit is contained in:
Michael S. Klishin 2011-08-16 00:06:40 +04:00
parent 8bd4378f93
commit b3d82ce3a2
2 changed files with 18 additions and 4 deletions

View file

@ -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

View file

@ -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"]