Liking cljdoc? Tell your friends :D

com.timezynk.mongo.util

Convenience functions for automating certain tasks.

Convenience functions for automating certain tasks.
raw docstring

->object-id?clj

(->object-id? o)

Return ObjectId for convertible object, or nil.

Return `ObjectId` for convertible object, or `nil`.
sourceraw docstring

->stringcljmultimethod

Convert to string.

Convert to string.
sourceraw docstring

discard-index!clj

(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.
sourceraw docstring

invoke-callbackclj

(invoke-callback)
source

make-collection!cljmacro

(make-collection! coll & {:as options})

Try to create a collection. If it already exists, modify it.

Try to create a collection. If it already exists, modify it.
sourceraw docstring

make-insert!clj

(make-insert! coll doc)

This is identical to insert!, except if payload is nil, return nil instead of throwing exception. Use this function when the payload is expected to be a nil-able document.

This is identical to `insert!`, except if payload is `nil`, return `nil` instead of throwing exception.
Use this function when the payload is expected to be a `nil`-able document.
sourceraw docstring

ObjectId?cljprotocol

object-id?clj

(object-id? v)

Check if ObjectId or valid string.

Check if `ObjectId` or valid string.
source

OBJECTID_REGEXclj

source

random-stringclj

(random-string size)
source

set-connection-callback!clj

(set-connection-callback! <callback-fn>)

Add a callback function that is executed when wrap-mongo initiates a new connection. The function is executed inside the new context.

Certain operations should only be done once per connection, such as initating new watch streams, but wrap-mongo is opaque. Therefore this work-around is needed.

Add a callback function that is executed when `wrap-mongo` initiates a new connection. The function is executed inside the new context.
    
Certain operations should only be done once per connection, such as initating new watch streams, but `wrap-mongo` is opaque.
Therefore this work-around is needed.
sourceraw docstring

set-mongo-uri!clj

(set-mongo-uri! <uri>
                &
                :retry-reads? <boolean>
                :retry-writes? <boolean>
                :read-concern [:available :default :linearizable :local
                               :majority :snapshot]
                :write-concern [:acknowledged :journaled :majority
                                :unacknowledged :w1 :w2 :w3])

Set connection string prior to creating a persistent binding.

ParameterDescription
uristring Database location.
:read-concernoptional keyword enum Set read concern:
:available The query returns data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
:default Sets the default concern, which is usually local
:linearizable The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation.
:local The query returns data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
:majority The query returns the data that has been acknowledged by a majority of the replica set members. The documents returned by the read operation are durable, even in the event of failure.
:snapshot Returns majority-committed data as it appears across shards from a specific single point in time in the recent past.
Read more about read concerns.
:retry-reads?optional boolean Sets whether reads should be retried if they fail due to a network error.
:retry-writes?optional boolean Sets whether writes should be retried if they fail due to a network error.
:write-concernoptional keyword enum Set write concern:
:acknowledged Write operations that use this write concern will wait for acknowledgement. Default.
:journaled Wait for the server to group commit to the journal file on disk.
:majority Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation. Usually the default option.
:unacknowledged Return as soon as the message is written to the socket.
:w1 Wait for acknowledgement from a single member.
:w2 Wait for acknowledgement from two members.
:w3 Wait for acknowledgement from three members.
Read more about write concerns.
Set connection string prior to creating a persistent binding.

| Parameter        | Description
| ---              | ---
| `uri`            | `string` Database location.
| `:read-concern`  | `optional keyword enum` Set read concern:
|                  | `:available` The query returns data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
|                  | `:default` Sets the default concern, which is usually `local`
|                  | `:linearizable` The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation.
|                  | `:local` The query returns data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
|                  | `:majority` The query returns the data that has been acknowledged by a majority of the replica set members. The documents returned by the read operation are durable, even in the event of failure.
|                  | `:snapshot` Returns majority-committed data as it appears across shards from a specific single point in time in the recent past.
|                  | [Read more about read concerns](https://www.mongodb.com/docs/manual/reference/read-concern/).
| `:retry-reads?`  | `optional boolean` Sets whether reads should be retried if they fail due to a network error.
| `:retry-writes?` | `optional boolean` Sets whether writes should be retried if they fail due to a network error.
| `:write-concern` | `optional keyword enum` Set write concern:
|                  | `:acknowledged` Write operations that use this write concern will wait for acknowledgement. Default.
|                  | `:journaled` Wait for the server to group commit to the journal file on disk.
|                  | `:majority` Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation. Usually the default option.
|                  | `:unacknowledged` Return as soon as the message is written to the socket.
|                  | `:w1` Wait for acknowledgement from a single member.
|                  | `:w2` Wait for acknowledgement from two members.
|                  | `:w3` Wait for acknowledgement from three members.
|                  | [Read more about write concerns](https://www.mongodb.com/docs/manual/reference/write-concern/).
sourceraw docstring

ToObjectIdcljprotocol

->object-idclj

(->object-id v)

Convert to ObjectId.

Convert to `ObjectId`.
source

type-byte-arraycljmacro

(type-byte-array)
source

wrap-mongocljmacro

(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.

  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.

ParameterDescription
bodyEncapsulated 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))
```
sourceraw docstring

wrap-requestclj

(wrap-request <handler>)

Wrap a request for a middleware setup

ParameterDescription
handlerfn 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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close