A clojure wrapper for the com.mongodb.client Java API. Loosely based on the somnium/congomongo toolkit.
The wrapper is intended to be functional, and not introduce state changes to a program environment.
Functions that add an environment or special conditions for other functions.
(with-mongo <connection> <database> <body>)
Sets up a connection with a database.
Example:
(with-mongo "mongodb://localhost:27017" "my-database"
(insert! :users {:name "My Name"})
(fetch! :users))
(with-db <database> <body>)
Switch database.
Example:
(with-db "my-database-2"
(insert! :users {:name "My Name"})
(fetch! :users))
(transaction <body>)
All database calls in the body are collected and executed atomically at end of scope.
Example:
(transaction
(insert! :users {:name "My Name"})
(fetch! :users))
Functions for making database requests.
(fetch <collection>)
(fetch <collection> <filter> <options>)
You need MongoDB version 4.4 or later installed.
Create a database folder:
mkdir mongodb
Start a server:
mongod --replSet rs0 --dbpath ./mongodb --port 27017
In a new terminal window, start the replica set:
mongo --eval "rs.initiate({ \"_id\": \"rs0\", members: [{ \"_id\": 0, host: \"localhost:27017\" }]}, { force: true })"
Start testing.
Can you improve this documentation? These fine people already did:
lars-timezynk & LarsEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close