Skip to content
Integrant methods for connecting to a MongoDB database via Monger
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Duct database.mongodb.monger

Build Status

Integrant methods for connecting to a MongoDB database via Monger.


To install, add the following to your project :dependencies

[me.grison/duct-mongodb "0.1.1"]


This library provides two things:

  • a Boundary record that holds both the Monger connection (:conn) and the selected database (:db).
  • a multimethod for :duct.database.mongodb/monger that initiates the connection based on those options into the Boundary.

When you write functions against the MongoDB database, consider using a protocol and extending the Boundary record. This will allow you to easily mock or stub out the database using a tool like Shrubbery.

Connection settings


  {:uri "mongodb://"}

Additional parameters can be used in the URI format.

Host & port

  {:host "", :port 27017, :db-name "hello"}}

Host & port with extended options

  {:host "", :port 27017, :db-name "hello"
   :options {:socket-timeout 1234
             :threads-allowed-to-block-for-connection-multiplier 300}}}

See MongoOptions for more information.


Consider a MongoDB database where a users collection exist, containing documents having at least a username field.

The database connection can be extracted from this module Boundary by using the :db key.

If you need access to the whole connection you can do so using the :conn key.

(ns my-project.boundary.user-db
  (:require [duct.database.mongodb.monger]
            [monger.collection :as mc]))
(defprotocol UserDatabase
  (get-user [db username]))
(extend-protocol UserDatabase
  (get-user [{:keys [db]} username]
    (mc/find db "users" {:username username})))

For more information using Monger, you can start with their getting started webpage.

Building & testing this library

If you already have a mongodb running on your machine just type lein test

If you don't have mongodb installed on your machine you can type lein embongo test which will download an embedded mongodb and run it during the test phase.


Copyright © 2018 Alexandre Grison

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

You can’t perform that action at this time.