Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

207 lines (125 sloc) 7.218 kb

Changes between 1.0.0-beta4 and 1.0.0-beta5

No changes yet.

Changes between 1.0.0-beta3 and 1.0.0-beta4

Support for URI connections (and thus PaaS provides like Heroku)

monger.core/connect-via-uri! is a new function that combines monger.core/connect!, monger.core/set-db! and monger.core/authenticate and works with string URIs like mongodb://

It can be used to connect with or without authentication, for example:

;; connect without authentication
(monger.core/connect-via-uri! "mongodb://")

;; connect with authentication
(monger.core/connect-via-uri! "mongodb://clojurewerkz/monger!:monger!@")

;; connect using connection URI stored in an env variable, in this case, MONGOHQ_URL
(monger.core/connect-via-uri! (System/genenv "MONGOHQ_URL"))

It is also possible to pass connection options and query parameters:

(monger.core/connect-via-uri! "mongodb://localhost/test?maxPoolSize=128&waitQueueMultiple=5;waitQueueTimeoutMS=150;socketTimeoutMS=5500&autoConnectRetry=true;safe=false&w=1;wtimeout=2500;fsync=true")

Changes between 1.0.0-beta2 and 1.0.0-beta3

Support for field negation in queries

Previously to load only a subset of document fields with Monger, one had to specify them all. Starting with 1.0.0-beta3, Monger supports field negation feature of MongoDB: it is possible to exclude certain fields instead.

To do so, pass a map as field selector, with fields that should be omitted set to 0:

;; will retrieve all fields except body
(monger.collection/find-one-map "documents" {:author "John"} {:body 0})

Validateur 1.1.0-beta1

Validateur dependency has been upgraded to 1.1.0-beta1.

Index Options support for monger.collection/ensure-index and /create-index

monger.collection/ensure-index and /create-index now accept index options as additional argument. Breaking change: 3-arity versions of those functions now become 4-arity versions.

Support serialization of Clojure ratios

Documents that contain Clojure ratios (for example, 26/5) now can be converted to DBObject instances and thus stored. On load, ratios will be presented as doubles: this way we ensure interoperability with other languages and clients.

Factories/fixtures DSL

When working with even moderately complex data sets, fixture data quickly becomes difficult to maintain. Monger 1.0.0-beta3 introduce a new factories DSL that is inspired by (but does not try to copy) Ruby's Factory Girl and similar libraries.

It includes support dynamically evaluated attributes and support for two most common techniques for implementing associations between documents.

Here is what it feels like:

(defaults-for "domains"
  :ipv6-enabled false)

(factory "domains" "clojure"
         :name       ""
         :created-at (-> 2 days ago)
         :embedded   [(embedded-doc "pages" "")
                      (embedded-doc "pages" "")
                      (embedded-doc "pages" "")])

(factory "domains" "elixir"
         :name     ""
         :created-at (fn [] (now))
         :topics     (fn [] ["programming" "erlang" "beam" "ruby"])
         :related    {
                      :terms (fn [] ["erlang" "python" "ruby"])

(factory "pages" ""
         :name "/rationale"
         :domain-id (parent-id "domains" "clojure"))
(factory "pages" ""
         :name "/jvm_hosted")
(factory "pages" ""
         :name "/runtime_polymorphism")
(factory "pages" ""
         :name "/lisp")

(build "domains" "clojure" :created-at (-> 2 weeks ago))
(seed  "pages" "")

Leiningen 2

Monger now uses Leiningen 2.


monger.core/set-connection! allows you to instantiate connection object (com.mongodb.Mongo instances) any way you like and then use it as default Monger connection. MongoDB Java driver provides many ways to instantiate and fine tune connections, this is the easiest way for Monger to support them all.

2-arity for monger.core/connect and monger.core/connect!

monger.core/connect now has 2-arity that accepts com.mongodb.ServerAddresss and com.mongodb.MongoOptions instances and allows you fine tune parameters like socket and connection timeouts, default :w value, connection threads settings and so on.

monger.core/mongo-options and monger.core/server-address are helper functions that instantiate those classes from paramters passed as Clojure maps, for convenience.

Changes between 1.0.0-beta1 and 1.0.0-beta2

3-arity of monger.collection/find-one-as-map now takes a vector of fields

3-arity of monger.collection/find-one-as-map now takes a vector of fields instead of keywordize to better fit a more commonly needed case.

;; 3-arity in 1.0.0-beta1
(monger.collection/find-one-as-map "documents" { :first_name "John" } false)
;; 3-arity in 1.0.0-beta2
(monger.collection/find-one-as-map "documents" { :first_name "John" } [:first_name, :last_name, :age])

If you need to use keywordize, use 4-arity:

(monger.collection/find-one-as-map "documents" { :first_name "John" } [:first_name, :last_name, :age] false)

Query DSL has a way to specify if fields need to be keywordized

It is now possible to opt-out of field keywordization in the query DSL:

(with-collection coll
  (find {})
  (limit 3)
  (sort { :population -1 })
  (keywordize-fields false))

the default value is still true, field names will be converted to keywords.

monger.collection/find-by-id and /find-map-by-id fail fast when id is nil

monger.collection/find-by-id and /find-map-by-id now will throw IllegalArgumentException when id is nil

monger.collection/find-map-by-id no longer ignore fields argument

monger.collection/find-map-by-id no longer ignore fields argument. Contributed by Toby Hede.

Meet monger.db and monger.command

monger.db namespace was added to perform operations like adding users or dropping databases. Several functions from monger.core will eventually be moved there, but not for 1.0.

monger.command namespace includes convenience methods for issuing MongoDB commands.

Both are contributed by Toby Hede.

New convenience functions: monger.collection/update-by-id, /remove-by-id

monger.collection/update-by-id is a new convenience function for updating a single document with given ObjectId. monger.collection/remove-by-id is its counterpart for removing documents.


monger.core/get-db-names returns a set of databases. Contributed by Toby Hede.

Jump to Line
Something went wrong with that request. Please try again.