mguinada/mongodb.async

Asynchronous MongoDB client for Clojure


Keywords
asynchronous, clojure, driver, mongodb
License
EPL-1.0

Documentation

mongodb.async


Clojars Project Build Status

Asynchronous MongoDB client for Clojure

Disclaimer

Not production ready. API can be the subject of changes. Use at your own risk.

Usage

All functions that map to MongoDB operations dispatch on double arity.

They can either be called with a callback (fn [result exception] ...) as the last argument or the call can omit the callback and thus return a core.async channel.

Here are some usage samples over the MongoDB primer dataset

connect
(require '[mongodb.async :as m])
(require '[clojure.core.async :as async :refer [<!!]])

(def db (m/connect :test))
fetch one (with callback)
(m/fetch-one db :restaurants :where {:cuisine "Continental"} (fn [rs ex]
                                                              (if-not ex
                                                                (println "result:" rs)
                                                                (println "error:" ex))))
fetch many
(<!! (m/fetch db :restaurants :where {:$or [{:cuisine "Continental"} {:cuisine "Mediterranean"}]} :limit 3))
count
(<!! (m/fetch-count db :restaurants :where {:cuisine "Continental"}))
insert
(<!! (m/insert! db :restaurants {:name "Catering Inc." :cuisine "American"}))
insert many
(<!! (m/insert-many! db :restaurants [{:name "Domino's Pizza" :cuisine "Pizza"} {:name "Pizza Hut" :cuisine "Pizza"}]))
replace
(<!! (m/replace-one! db :restaurants {:name "Catering"} :where {:name "Catering Inc."}))
remove
(<!! (m/remove! db :restaurants :where {:name "Catering Inc."}))
remove one
(<!! (m/remove-one! db :restaurants :where {:name "Domino's Pizza"}))

What's missing

  • Database authentication
  • Aggregation primitives
  • Map/Reduce primitives
  • Support for DbRefs
  • Write concerns
  • Read preferences
  • Add/Remove index

Influences

Resources

License

Copyright © 2017 Miguel Guinada
Distributed under the Eclipse Public License