Liking cljdoc? Tell your friends :D

com.timezynk.mongo.hooks


ignore-hookscljmacro

(ignore-hooks & <body>)

If any hooks are set, ignore them.

ParameterDescription
bodyEncapsulated program for which database hooks are to be ignored.
If any hooks are set, ignore them.

| Parameter | Description
| ---       | ---
| `body`    | Encapsulated program for which database hooks are to be ignored.
sourceraw docstring

with-hookscljmacro

(with-hooks {:read <read-fn> :write <write-fn>} & <body>)

Insert hooks for converting documents. The <read-fn> function will be called for each document returned from MongoDB; the <write-fn> will be called for each document sent to MongoDB, both for the query and for the payload.

The hook is applied recursively to nested documents.

ParameterDescription
:readoptional fn Called when returning a document from MongoDB.
:writeoptional fn Called for a query or payload to MongoDB.
bodyEncapsulated program calling the database.

Examples

; When a document is written to the database, replace the field 'name' with 'username':
(with-hooks {:write #(clojure.set/rename-keys % {:name :username})}
  (insert! :coll {:name "My Name"}))
Insert hooks for converting documents. The <read-fn> function will be called for each document
returned from MongoDB; the <write-fn> will be called for each document sent to MongoDB, both
for the query and for the payload.

The hook is applied recursively to nested documents.

| Parameter | Description
| ---       | ---
| `:read`   | `optional fn` Called when returning a document from MongoDB.
| `:write`  | `optional fn` Called for a query or payload to MongoDB.
| `body`    | Encapsulated program calling the database.

**Examples**

```clojure
; When a document is written to the database, replace the field 'name' with 'username':
(with-hooks {:write #(clojure.set/rename-keys % {:name :username})}
  (insert! :coll {:name "My Name"}))
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close