diff --git a/src/monger/core.clj b/src/monger/core.clj index 7ee65b0..0db791b 100644 --- a/src/monger/core.clj +++ b/src/monger/core.clj @@ -52,6 +52,15 @@ ([{ :keys [host port] :or { host *mongodb-host*, port *mongodb-port* }}] (Mongo. ^String host ^Long port))) + + +(defn ^DB get-db-names + "Gets a list of all database names present on the server" + ([] + (list (.getDatabaseNames *mongodb-connection*))) + ([^Mongo connection] + (list (.getDatabaseNames connection)))) + (defn ^DB get-db "Get database reference by name. diff --git a/test/monger/test/core.clj b/test/monger/test/core.clj index 62b7513..d50c768 100644 --- a/test/monger/test/core.clj +++ b/test/monger/test/core.clj @@ -28,6 +28,13 @@ (is (instance? com.mongodb.DB db)))) +(deftest test-get-db-names + (let [dbs (monger.core/get-db-names)] + (is (not (empty? dbs))) + (is (some #{"monger-test"} dbs)) + ) +) + ;; (deftest get-database-with-valid-credentials ;; (let [connection (monger.core/connect) ;; db (monger.core/get-db connection "monger-test" "monger" "test_password")]