Convenience functions for automating certain tasks.
Convenience functions for automating certain tasks.
(discard-index! coll index)Try to drop an index. If it doesn't exist, ignore the exception.
Try to drop an index. If it doesn't exist, ignore the exception.
(make-collection! coll & options)Try to create a collection. If it already exists, modify it.
Try to create a collection. If it already exists, modify it.
(set-mongo-uri! <uri>)Set connection string prior to creating a persistent binding.
| Parameter | Description |
|---|---|
uri | string Database location. |
Set connection string prior to creating a persistent binding. | Parameter | Description | --- | --- | `uri` | `string` Database location.
Convert to ObjectId.
Convert to ObjectId.
(->object-id v)(wrap-mongo & <body>)Functionally set up or change mongodb connection, creating a persistent connection from a previously defined connection string. Reverts to earlier settings when leaving scope.
set-mongo-uri!.MONGO_URI environment variable.The connection string is used only once to set up the persistent connection.
| Parameter | Description |
|---|---|
body | Encapsulated program calling the database. |
Returns
The result of the last encapsulated expression.
Examples
(set-mongo-uri! "mongodb://localhost:27017/my-database")
(wrap-mongo
(insert! :users {:name "My Name"})
(fetch! :users))
Functionally set up or change mongodb connection, creating a persistent connection from a previously defined connection string.
Reverts to earlier settings when leaving scope.
1. Looks for a connection string set by a prior call to `set-mongo-uri!`.
2. Failing that, retrieves a connection string `MONGO_URI` environment variable.
The connection string is used only once to set up the persistent connection.
| Parameter | Description
| --- | ---
| `body` | Encapsulated program calling the database.
**Returns**
The result of the last encapsulated expression.
**Examples**
```clojure
(set-mongo-uri! "mongodb://localhost:27017/my-database")
(wrap-mongo
(insert! :users {:name "My Name"})
(fetch! :users))
```(wrap-request <handler>)Wrap a request for a middleware setup
| Parameter | Description |
|---|---|
handler | fn A request handler function. |
Returns
A function that takes a request paramater and makes a call to handler with that request, inside a wrap-mongo call.
Wrap a request for a middleware setup | Parameter | Description | --- | --- | `handler` | `fn` A request handler function. **Returns** A function that takes a `request` paramater and makes a call to `handler` with that request, inside a `wrap-mongo` call.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |