Introduce monger.core/Countable protocol
This commit is contained in:
parent
1bba60418e
commit
8bd4378f93
2 changed files with 11 additions and 1 deletions
|
|
@ -40,3 +40,13 @@
|
|||
(.getDB *mongodb-connection* name))
|
||||
([^Mongo connection, ^String name]
|
||||
(.getDB connection name)))
|
||||
|
||||
|
||||
|
||||
(defprotocol Countable
|
||||
(count [this] "Returns size of the object"))
|
||||
|
||||
(extend-protocol Countable
|
||||
com.mongodb.DBCursor
|
||||
(count [^com.mongodb.DBCursor this]
|
||||
(.count this)))
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@
|
|||
(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 (= 1 (.count (monger.collection/find collection { :language "Scala" }))))
|
||||
(is (= 1 (monger.core/count (monger.collection/find collection { :language "Scala" }))))
|
||||
(is (= 3 (.count (monger.collection/find collection { :language "Clojure" }))))
|
||||
(is (empty? (monger.collection/find collection { :language "Java" })))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue