Merge branch 'chrisbroome-more-meaningful-uri-exception'

This commit is contained in:
Michael Klishin 2018-12-07 19:52:12 +03:00
commit 85c7b84d13
No known key found for this signature in database
GPG key ID: 2C0DA45F4F944489
4 changed files with 11 additions and 6 deletions

View file

@ -1,8 +1,8 @@
language: clojure
sudo: required
lein: lein
dist: xenial
before_script:
- ./bin/ci/install_mongodb.sh
- mongod --version
- ./bin/ci/before_script.sh
script: lein do clean, javac, test

View file

@ -1,7 +1,7 @@
#!/bin/sh
# MongoDB seems to need some time to boot first. MK.
sleep 5
sleep 15
# MongoDB Java driver won't run authentication twice on the same DB instance,
# so we need to use multiple DBs.

View file

@ -234,9 +234,10 @@
If username and password are provided, performs authentication."
[^String uri-string]
(let [uri (MongoClientURI. uri-string)
conn (MongoClient. uri)
db (.getDB conn (.getDatabase uri))]
{:conn conn :db db}))
conn (MongoClient. uri)]
(if-let [dbName (.getDatabase uri)]
{:conn conn :db (.getDB conn dbName)}
(throw (IllegalArgumentException. "No database name specified in URI. Monger requires a database to be explicitly configured.")))))
(defn ^com.mongodb.CommandResult command
"Runs a database command (please check MongoDB documentation for the complete list of commands).

View file

@ -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? IllegalArgumentException (mg/connect-via-uri uri)))))