Sync with upstream

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
This commit is contained in:
Michael Klishin 2014-02-08 19:02:02 +04:00
commit 3c951a0828
2 changed files with 23 additions and 4 deletions

View file

@ -1,3 +1,14 @@
## Changes between 1.7.0 and 1.8.0-beta1
### monger.core/connect-via-uri
`monger.core/connect-via-uri` is a version of `monger.core/connect-via-uri!`
which returns the connection instead of mutating a var.
It should be used by projects that are built from reloadable
components, together with `monger.multi.*`.
## Changes between 1.7.0-beta1 and 1.7.0
### MongoDB Java Driver Update

View file

@ -223,9 +223,10 @@
(catch Exception _
false))))
(defn connect-via-uri!
"Connects to MongoDB using a URI, sets up default connection and database. Commonly used for PaaS-based applications,
for example, running on Heroku. If username and password are provided, performs authentication."
(defn connect-via-uri
"Connects to MongoDB using a URI, returns the connection and database as a map with :conn and :db.
Commonly used for PaaS-based applications, for example, running on Heroku.
If username and password are provided, performs authentication."
[^String uri-string]
(let [uri (MongoClientURI. uri-string)
conn (MongoClient. uri)
@ -235,7 +236,14 @@
(when (and user pwd)
(when-not (authenticate conn db user pwd)
(throw (IllegalArgumentException. (format "Could not authenticate with MongoDB. Either database name or credentials are invalid. Database name: %s, username: %s" (.getName db) user)))))
;; only do this *after* we authenticated because set-db! will try to set up a default GridFS instance. MK.
{:conn conn, :db db}))
(defn connect-via-uri!
"Connects to MongoDB using a URI, sets up default connection and database. Commonly used for PaaS-based applications,
for example, running on Heroku. If username and password are provided, performs authentication."
[uri-string]
(let [{:keys [conn db]} (connect-via-uri uri-string)]
(set-connection! conn)
(when db
(set-db! db))