This is a very simple example for how to use mongo-db using the tesla-mongo-connect addon to tesla-microservice.
To start the application you can either use
-
a mongo-db running on localhost (or whatever you change the config to in default.edn). Then you can start the application with
lein run
-
an embedded mongodb provided by embongo. Start the application with
lein embongo run
.
The project contains a page, which is dependent on :mongo
in tesla-mongo-connect. The page displays the database content and a form to add a document to the collection in the database.
If you call http://localhost:8080/example
the data is read out of mongo and rendered into the html-response in page.clj:
(mongo/find-checked! (:mongo self) "collection" {})
The form data is processed by the page.clj via POST:
(mongo/update-upserting! mongo "collection" {:_id col}
{$push
{(keyword key) value}})