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 language: clojure
sudo: required sudo: required
lein: lein lein: lein
dist: xenial
before_script: before_script:
- ./bin/ci/install_mongodb.sh
- mongod --version - mongod --version
- ./bin/ci/before_script.sh - ./bin/ci/before_script.sh
script: lein do clean, javac, test script: lein do clean, javac, test

View file

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

View file

@ -233,10 +233,11 @@
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))] (if-let [dbName (.getDatabase uri)]
{:conn conn :db db})) {: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 (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).

View file

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