I started to develop using Clojure luminus framework with mongodb (with monger library).
It was very hard to understand how to implement mount library to start the db connection.
I figured out that code should put handler.clj 's init function.
But I cannot figure out how to tell mount to start the database connection.
Please could you give me a hand?
Here gores my development config.clj
(ns vippro.config
(:require [selmer.parser :as parser]
[clojure.tools.logging :as log]
[vippro.dev-middleware :refer [wrap-dev]]
))
(def defaults
{:init
(fn []
(parser/cache-off!)
(log/info "\n-=[vippro started successfully using the development profile]=-"))
:middleware wrap-dev})
and in handler.clj 's init function
(defn init
"init will be called once when
app is deployed as a servlet on
an app server such as Tomcat
put any initialization code here"
[]
(when-let [config (:log-config env)]
(org.apache.log4j.PropertyConfigurator/configure config))
(doseq [component (:started (mount/start))]
(log/info component "started"))
((:init defaults)))
my main problem is how should I call this function from init proper way
(defn connect! []
;; Tries to get the Mongo URI from the environment variable
(reset! db (-> (:database-url env) mg/connect-via-uri :db)))