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
|
|
@ -235,8 +235,11 @@
|
|||
[^String uri-string]
|
||||
(let [uri (MongoClientURI. uri-string)
|
||||
conn (MongoClient. uri)
|
||||
db (.getDB conn (.getDatabase uri))]
|
||||
{:conn conn :db db}))
|
||||
dbName (.getDatabase uri)]
|
||||
(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
|
||||
"Runs a database command (please check MongoDB documentation for the complete list of commands).
|
||||
|
|
|
|||
|
|
@ -70,3 +70,7 @@
|
|||
:cursor-finalizer-enabled true
|
||||
:required-replica-set-name "rs"}]
|
||||
(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