Add monger.collection/count version that takes conditions argument
This commit is contained in:
parent
8bd4378f93
commit
b3d82ce3a2
2 changed files with 18 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue