Explicit database parameter for monger.collection/insert-batch, /count, /empty?, /any?
This commit is contained in:
parent
e5af694cc7
commit
afa516fff6
2 changed files with 26 additions and 8 deletions
|
|
@ -58,6 +58,9 @@
|
|||
(.insert ^DBCollection coll ^List (to-db-object documents) ^WriteConcern monger.core/*mongodb-write-concern*)))
|
||||
([^String collection, ^List documents, ^WriteConcern concern]
|
||||
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
||||
(.insert ^DBCollection coll ^List (to-db-object documents) ^WriteConcern concern)))
|
||||
([^DB db ^String collection, ^List documents, ^WriteConcern concern]
|
||||
(let [^DBCollection coll (.getCollection db collection)]
|
||||
(.insert ^DBCollection coll ^List (to-db-object documents) ^WriteConcern concern))))
|
||||
|
||||
;;
|
||||
|
|
@ -201,6 +204,9 @@
|
|||
(.count coll)))
|
||||
(^long [^String collection, ^Map conditions]
|
||||
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
||||
(.count coll (to-db-object conditions))))
|
||||
(^long [^DB db ^String collection, ^Map conditions]
|
||||
(let [^DBCollection coll (.getCollection db collection)]
|
||||
(.count coll (to-db-object conditions)))))
|
||||
|
||||
(defn any?
|
||||
|
|
@ -216,7 +222,9 @@
|
|||
([^String collection]
|
||||
(> (count collection) 0))
|
||||
([^String collection, ^Map conditions]
|
||||
(> (count collection conditions) 0)))
|
||||
(> (count collection conditions) 0))
|
||||
([^DB db ^String collection, ^Map conditions]
|
||||
(> (count db collection conditions) 0)))
|
||||
|
||||
|
||||
(defn empty?
|
||||
|
|
@ -226,7 +234,9 @@
|
|||
(mgcol/empty? \"things\")
|
||||
"
|
||||
([^String collection]
|
||||
(= (count collection) 0)))
|
||||
(= (count collection) 0))
|
||||
([^DB db ^String collection]
|
||||
(= (count db collection {}) 0)))
|
||||
|
||||
;; monger.collection/update
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,13 @@
|
|||
(is (monger.result/ok? (mgcol/insert-batch "people" docs WriteConcern/NORMAL)))
|
||||
(is (= 2 (mgcol/count collection)))))
|
||||
|
||||
(deftest insert-a-batch-of-basic-documents-with-explicit-database-without-ids-and-with-explicit-write-concern
|
||||
(let [collection "people"
|
||||
docs [{ :name "Joe", :age 30 }, { :name "Paul", :age 27 }]]
|
||||
(dotimes [n 44]
|
||||
(is (monger.result/ok? (mgcol/insert-batch monger.core/*mongodb-database* "people" docs WriteConcern/NORMAL))))
|
||||
(is (= 88 (mgcol/count collection)))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -91,12 +98,12 @@
|
|||
{ :language "Scala", :name "akka" }] )
|
||||
(is (= 4 (mgcol/count collection)))
|
||||
(is (mgcol/any? collection))
|
||||
(is (= 3 (mgcol/count collection { :language "Clojure" })))
|
||||
(is (mgcol/any? collection { :language "Clojure" }))
|
||||
(is (= 3 (mgcol/count monger.core/*mongodb-database* collection { :language "Clojure" })))
|
||||
(is (mgcol/any? monger.core/*mongodb-database* collection { :language "Clojure" }))
|
||||
(is (= 1 (mgcol/count collection { :language "Scala" })))
|
||||
(is (mgcol/any? collection { :language "Scala" }))
|
||||
(is (= 0 (mgcol/count collection { :language "Python" })))
|
||||
(is (not (mgcol/any? collection { :language "Python" })))))
|
||||
(is (= 0 (mgcol/count monger.core/*mongodb-database* collection { :language "Python" })))
|
||||
(is (not (mgcol/any? monger.core/*mongodb-database* collection { :language "Python" })))))
|
||||
|
||||
|
||||
(deftest remove-all-documents-from-collection
|
||||
|
|
@ -543,11 +550,12 @@
|
|||
(let [collection "things"
|
||||
_ (mgcol/insert collection { :language "Clojure", :name "langohr" })]
|
||||
(is (mgcol/any? "things"))
|
||||
(is (mgcol/any? "things" {:language "Clojure"}))))
|
||||
(is (mgcol/any? monger.core/*mongodb-database* "things" {:language "Clojure"}))))
|
||||
|
||||
(deftest empty-on-empty-collection
|
||||
(let [collection "things"]
|
||||
(is (mgcol/empty? collection))))
|
||||
(is (mgcol/empty? collection))
|
||||
(is (mgcol/empty? monger.core/*mongodb-database* collection))))
|
||||
|
||||
(deftest empty-on-non-empty-collection
|
||||
(let [collection "things"
|
||||
|
|
|
|||
Loading…
Reference in a new issue