diff --git a/src/monger/core.clj b/src/monger/core.clj index 90fe581..e538bc9 100644 --- a/src/monger/core.clj +++ b/src/monger/core.clj @@ -170,6 +170,14 @@ [^Map 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 (count [this] "Returns size of the object")) diff --git a/test/monger/test/core.clj b/test/monger/test/core.clj index 3f14d0a..c43bd1b 100644 --- a/test/monger/test/core.clj +++ b/test/monger/test/core.clj @@ -1,6 +1,7 @@ (ns monger.test.core (: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)) (:use [clojure.test])) @@ -26,6 +27,15 @@ db (monger.core/get-db connection "monger-test")] (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 ;; (let [connection (monger.core/connect) ;; db (monger.core/get-db connection "monger-test" "monger" "test_password")]