Skip to content

Instantly share code, notes, and snippets.

@nilswloka
Created February 28, 2012 19:12
Show Gist options
  • Save nilswloka/1934452 to your computer and use it in GitHub Desktop.
Save nilswloka/1934452 to your computer and use it in GitHub Desktop.
Use mongeez with congomongo
(ns example
(:use somnium.congomongo)
(:use [somnium.congomongo.config :only [*mongo-config*]])
(:import [org.mongeez Mongeez])
(:import [org.springframework.core.io ClassPathResource]))
(defn migrate-mongo [db]
"Migrates mongodb by using mongeez"
(let [mongo (:mongo *mongo-config*)
mongeez (Mongeez.)]
(doto mongeez
(.setFile (ClassPathResource. "/mongeez.xml"))
(.setMongo mongo)
(.setDbName db)
(.process))))
(defn init-mongo []
(when (not (connection? *mongo-config*))
(let [host "localhost"
port 27017
db "example"
(mongo! :db db :host host :port port)
(migrate-mongo db))))
(init-mongo)
<changeFiles>
<file path="mongo-change-1.xml"/>
</changeFiles>
<mongoChangeLog>
<changeSet changeId="ChangeSet-1" author="example-author">
<script>
example = { greeting : 'Hello World!' };
db.greetings.insert(example);
</script>
</changeSet>
</mongoChangeLog>
(defproject example "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.3.0"]
[congomongo "0.1.7"]
[org.mongeez/mongeez "0.9.1"]
[log4j "1.2.16"]
[org.springframework/spring-core "3.0.5.RELEASE"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment