add get-collections-names to core
This commit is contained in:
parent
31aff189d3
commit
66e5e929ad
2 changed files with 19 additions and 1 deletions
|
|
@ -170,6 +170,14 @@
|
||||||
[^Map cmd]
|
[^Map cmd]
|
||||||
(.command ^DB *mongodb-database* ^DBObject (to-db-object cmd)))
|
(.command ^DB *mongodb-database* ^DBObject (to-db-object cmd)))
|
||||||
|
|
||||||
|
(defn ^Set get-collection-names
|
||||||
|
"Returns a set containing the names of all collections in this database.."
|
||||||
|
([]
|
||||||
|
(.getCollectionNames ^DB *mongodb-database*))
|
||||||
|
([^DB database]
|
||||||
|
(.getCollectionNames ^DB database))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
(defprotocol Countable
|
(defprotocol Countable
|
||||||
(count [this] "Returns size of the object"))
|
(count [this] "Returns size of the object"))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns monger.test.core
|
(ns monger.test.core
|
||||||
(:require [monger core collection util result]
|
(:require [monger core collection util result]
|
||||||
[monger.test.helper :as helper])
|
[monger.test.helper :as helper]
|
||||||
|
[monger.collection :as mgcol])
|
||||||
(:import (com.mongodb Mongo DB WriteConcern))
|
(:import (com.mongodb Mongo DB WriteConcern))
|
||||||
(:use [clojure.test]))
|
(:use [clojure.test]))
|
||||||
|
|
||||||
|
|
@ -26,6 +27,15 @@
|
||||||
db (monger.core/get-db connection "monger-test")]
|
db (monger.core/get-db connection "monger-test")]
|
||||||
(is (instance? com.mongodb.DB db))))
|
(is (instance? com.mongodb.DB db))))
|
||||||
|
|
||||||
|
|
||||||
|
(deftest get-collection-names
|
||||||
|
(mgcol/insert "test-1" { :name "Clojure" })
|
||||||
|
(mgcol/insert "test-2" { :name "Clojure" })
|
||||||
|
(let [collections (monger.core/get-collection-names)]
|
||||||
|
(is (.contains collections "test-1"))
|
||||||
|
(is (.contains collections "test-2"))
|
||||||
|
))
|
||||||
|
|
||||||
;; (deftest get-database-with-valid-credentials
|
;; (deftest get-database-with-valid-credentials
|
||||||
;; (let [connection (monger.core/connect)
|
;; (let [connection (monger.core/connect)
|
||||||
;; db (monger.core/get-db connection "monger-test" "monger" "test_password")]
|
;; db (monger.core/get-db connection "monger-test" "monger" "test_password")]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue