Add more descriptive error message when uri has no db name
This commit is contained in:
parent
4b591fc910
commit
aa08f4b58c
2 changed files with 11 additions and 4 deletions
|
|
@ -233,10 +233,13 @@
|
||||||
Commonly used for PaaS-based applications, for example, running on Heroku.
|
Commonly used for PaaS-based applications, for example, running on Heroku.
|
||||||
If username and password are provided, performs authentication."
|
If username and password are provided, performs authentication."
|
||||||
[^String uri-string]
|
[^String uri-string]
|
||||||
(let [uri (MongoClientURI. uri-string)
|
(let [uri (MongoClientURI. uri-string)
|
||||||
conn (MongoClient. uri)
|
conn (MongoClient. uri)
|
||||||
db (.getDB conn (.getDatabase uri))]
|
dbName (.getDatabase uri)]
|
||||||
{:conn conn :db db}))
|
(if (nil? dbName)
|
||||||
|
(throw (Exception. "No database name specified in uri"))
|
||||||
|
(let [db (.getDB conn dbName)]
|
||||||
|
{:conn conn :db db}))))
|
||||||
|
|
||||||
(defn ^com.mongodb.CommandResult command
|
(defn ^com.mongodb.CommandResult command
|
||||||
"Runs a database command (please check MongoDB documentation for the complete list of commands).
|
"Runs a database command (please check MongoDB documentation for the complete list of commands).
|
||||||
|
|
|
||||||
|
|
@ -70,3 +70,7 @@
|
||||||
:cursor-finalizer-enabled true
|
:cursor-finalizer-enabled true
|
||||||
:required-replica-set-name "rs"}]
|
:required-replica-set-name "rs"}]
|
||||||
(is (instance? com.mongodb.MongoClientOptions$Builder (mg/mongo-options-builder opts)))))
|
(is (instance? com.mongodb.MongoClientOptions$Builder (mg/mongo-options-builder opts)))))
|
||||||
|
|
||||||
|
(deftest connect-to-uri-without-db-name
|
||||||
|
(let [uri "mongodb://localhost:27017"]
|
||||||
|
(is (thrown? Exception (mg/connect-via-uri uri)))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue