Liking cljdoc? Tell your friends :D

com.timezynk.mongo

A functional Clojure wrapper for the modern Java MongoDB API.

A functional Clojure wrapper for the modern Java MongoDB API.
raw docstring

aggregateclj

(aggregate <collection> & <pipeline>)

MongoDB aggregation.

ParameterDescription
collectionkeyword/string Collection name.
pipelineThe request pipeline queries.

Returns

Aggregation result.

Examples

(aggregate :users
  {:$match {:age {:$gte 20}}}
  {:$project {:_id 0
              :name 1}})
MongoDB aggregation.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` Collection name.
| `pipeline`   | The request pipeline queries.

**Returns**

Aggregation result.

**Examples**

```clojure
(aggregate :users
  {:$match {:age {:$gte 20}}}
  {:$project {:_id 0
              :name 1}})
```
sourceraw docstring

close-connection!clj

(close-connection! conn)
source

collationcljmacro

(collation <locale>
           &
           :alternate [:non-ignorable :shifted]
           :backwards? <boolean>
           :case-first [:lower :off :upper]
           :case-level? <boolean>
           :max-variable [:punct :space]
           :normalization? <boolean>
           :numeric-ordering? <boolean>
           :strength [:identical :primary :quaternary :secondary :tertiary])

Create collation object.

ParameterDescription
localestring The two-letter ICU locale string.
:alternateoptional keyword enum Should whitespace and punctuation be considered as base characters for purposes of comparison?
:non-ignorable Whitespace and punctuation are considered base characters.
:shifted Whitespace and punctuation are not considered base characters and are only distinguished at strength levels greater than 3.
:backwards?optional boolean Whether strings with diacritics sort from back of the string, such as with some French dictionary ordering. Default is false.
:case-firstoptional keyword enum Sort order of case differences during tertiary level comparisons.
:lower Uppercase sorts before lowercase.
:upper Lowercase sorts before uppercase.
:off Default value. Similar to :lower with slight differences.
:case-level?optional boolean Flag that determines whether to include case comparison at strength level 1 or 2.
:max-variableoptional keyword enum Which characters are considered ignorable when :alternate = :shifted? Has no effect if :alternate = :non-ignorable.
:punct Both whitespace and punctuation are ignorable and not considered base characters.
:space Whitespace is ignorable and not considered to be base characters.
:normalization?optional boolean Check if text requires normalization and to perform normalization. Default is false.
:numeric-ordering?optional boolean Compare numeric strings as numbers or as strings. Default is false.
:strengthoptional keyword enum The level of comparison to perform.
:identical Limited for specific use case of tie breaker.
:primary Collation performs comparisons of the base characters only, ignoring other differences such as diacritics and case.
:secondary Collation performs comparisons up to secondary differences, such as diacritics. That is, collation performs comparisons of base characters (primary differences) and diacritics (secondary differences). Differences between base characters takes precedence over secondary differences.
:tertiary Collation performs comparisons up to tertiary differences, such as case and letter variants. That is, collation performs comparisons of base characters (primary differences), diacritics (secondary differences), and case and variants (tertiary differences). Differences between base characters takes precedence over secondary differences, which takes precedence over tertiary differences. Default level.
:quaternary Limited for specific use case to consider punctuation when levels 1-3 ignore punctuation or for processing Japanese text.

For more details, see the manual page on collation.

Returns

The collation object.

Examples

(collation)
Create collation object.

| Parameter            | Description
| ---                  | ---
| `locale`             | `string` The two-letter ICU locale string.
| `:alternate`         | `optional keyword enum` Should whitespace and punctuation be considered as base characters for purposes of comparison?
|                      | `:non-ignorable` Whitespace and punctuation are considered base characters.
|                      | `:shifted` Whitespace and punctuation are not considered base characters and are only distinguished at strength levels greater than 3.
| `:backwards?`        | `optional boolean` Whether strings with diacritics sort from back of the string, such as with some French dictionary ordering. Default is `false`.
| `:case-first`        | `optional keyword enum` Sort order of case differences during tertiary level comparisons.
|                      | `:lower` Uppercase sorts before lowercase.
|                      | `:upper` Lowercase sorts before uppercase.
|                      | `:off` Default value. Similar to `:lower` with slight differences.
| `:case-level?`       | `optional boolean` Flag that determines whether to include case comparison at strength level 1 or 2.
| `:max-variable`      | `optional keyword enum` Which characters are considered ignorable when `:alternate = :shifted`? Has no effect if `:alternate = :non-ignorable`.
|                      | `:punct` Both whitespace and punctuation are ignorable and not considered base characters.
|                      | `:space` Whitespace is ignorable and not considered to be base characters.
| `:normalization?`    | `optional boolean` Check if text requires normalization and to perform normalization. Default is `false`.
| `:numeric-ordering?` | `optional boolean` Compare numeric strings as numbers or as strings. Default is `false`.
| `:strength`          | `optional keyword enum` The level of comparison to perform.
|                      | `:identical` Limited for specific use case of tie breaker.
|                      | `:primary` Collation performs comparisons of the base characters only, ignoring other differences such as diacritics and case.
|                      | `:secondary` Collation performs comparisons up to secondary differences, such as diacritics. That is, collation performs comparisons of base characters (primary differences) and diacritics (secondary differences). Differences between base characters takes precedence over secondary differences.
|                      | `:tertiary` Collation performs comparisons up to tertiary differences, such as case and letter variants. That is, collation performs comparisons of base characters (primary differences), diacritics (secondary differences), and case and variants (tertiary differences). Differences between base characters takes precedence over secondary differences, which takes precedence over tertiary differences. Default level.
|                      | `:quaternary` Limited for specific use case to consider punctuation when levels 1-3 ignore punctuation or for processing Japanese text.

For more details, see the [manual page on collation](https://www.mongodb.com/docs/v5.3/reference/collation/).

**Returns**

The collation object.

**Examples**

```clojure
(collation)
```
sourceraw docstring

collection-infoclj

(collection-info coll)

List full info of collection.

ParameterDescription
namekeyword/string Collection name.
List full info of collection.

| Parameter | Description
| ---       | ---
| `name`    | `keyword/string` Collection name.
sourceraw docstring

connection-pool-statsclj

(connection-pool-stats)
source

create-collection!cljmacro

(create-collection! <name>
                    &
                    :collation
                    <collation
                    object>
                    :level [:strict :moderate :off]
                    :schema {}
                    :validation {})

Create collection.

ParameterDescription
namekeyword/string Collection name.
:collationoptional collation object The collation of the collection.
:schemaoptional map The schema validation map.
:validationoptional map Validation logic outside of the schema.
:leveloptional keyword enum Validaton level:
:strict Apply validation rules to all inserts and all updates. Default value.
:moderate Applies validation rules to inserts and to updates on existing valid documents.
:off No validation for inserts or updates.

Returns

The collection object.

Examples

; Collection with exactly one required field `name` of type `string`:
(create-collection! :users :schema {:name (string)})

; Collection where each document can have either a `name` field or an `address` field, but not both:
(create-collection! :users :validation {:$or [{:name {:$ne nil} :address {:$exists 0}}
                                              {:name {:$exists 0} :address {:$ne nil}}]})
Create collection.

| Parameter     | Description
| ---           | ---
| `name`        | `keyword/string` Collection name.
| `:collation`  | `optional collation object` The collation of the collection.
| `:schema`     | `optional map` The schema validation map.
| `:validation` | `optional map` Validation logic outside of the schema.
| `:level`      | `optional keyword enum` Validaton level:
|               | `:strict` Apply validation rules to all inserts and all updates. Default value.
|               | `:moderate` Applies validation rules to inserts and to updates on existing valid documents.
|               | `:off` No validation for inserts or updates.

**Returns**

The collection object.

**Examples**

```clojure
; Collection with exactly one required field `name` of type `string`:
(create-collection! :users :schema {:name (string)})

; Collection where each document can have either a `name` field or an `address` field, but not both:
(create-collection! :users :validation {:$or [{:name {:$ne nil} :address {:$exists 0}}
                                              {:name {:$exists 0} :address {:$ne nil}}]})
```
sourceraw docstring

create-connection!cljmacro

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

Create a connection object.

ParameterDescription
uristring Database location.
: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.
: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.
: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.

Returns

The connection object.

Examples

; Create a connection with default options
(create-connection! "mongodb://localhost:27017/my-database")

; Create a custom connection
(create-connection! "mongodb://localhost:27017/my-database" :retry-writes? true :write-concern :w2)
Create a connection object.

| Parameter        | Description
| ---              | ---
| `uri`            | `string` Database location.
| `: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.
| `: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/).
| `: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/).

**Returns**

The connection object.

**Examples**

```clojure
; Create a connection with default options
(create-connection! "mongodb://localhost:27017/my-database")

; Create a custom connection
(create-connection! "mongodb://localhost:27017/my-database" :retry-writes? true :write-concern :w2)
```
sourceraw docstring

create-index!cljmacro

(create-index! <collection>
               <keys>
               &
               :collation
               <collation
               object>
               :background? <boolean>
               :name <string>
               :filter {}
               :sparse? <boolean>
               :unique? <boolean>)

Create an index for a collection.

ParameterDescription
collectionkeyword/string Collection name.
keysmap/list(keyword/string) A document or a list of keywords or strings.
:collationoptional collation object Collation of index.
:background?optional boolean Create the index in the background. Default false.
:nameoptional string A custom name for the index.
:filteroptional map A partial-filter-expression for the index.
:sparse?optional boolean Don't index null values. Default false.
:unique?optional boolean Index values must be unique. Default false.

Returns

The index name.

Examples

; Index over field-1 in descending order, field-2 as hashed
(create-index! :coll {:field-1 -1 :field-2 "hashed"})

; Shorthand for indexing over fields in ascending order
(create-index! :coll [:field-1 :field-2])

; Only flagged documents are indexed and searchable
(create-index! :coll [:field-1] :filter {:flag-field true})
Create an index for a collection.

| Parameter      | Description
| ---            | ---
| `collection`   | `keyword/string` Collection name.
| `keys`         | `map/list(keyword/string)` A document or a list of keywords or strings.
| `:collation`   | `optional collation object` Collation of index.
| `:background?` | `optional boolean` Create the index in the background. Default `false`.
| `:name`        | `optional string` A custom name for the index.
| `:filter`      | `optional map` A partial-filter-expression for the index.
| `:sparse?`     | `optional boolean` Don't index null values. Default `false`.
| `:unique?`     | `optional boolean` Index values must be unique. Default `false`.

**Returns**

The index name.

**Examples**

```clojure
; Index over field-1 in descending order, field-2 as hashed
(create-index! :coll {:field-1 -1 :field-2 "hashed"})

; Shorthand for indexing over fields in ascending order
(create-index! :coll [:field-1 :field-2])

; Only flagged documents are indexed and searchable
(create-index! :coll [:field-1] :filter {:flag-field true})
```
sourceraw docstring

database-nameclj

(database-name)

Get the name of the currently active database.

Get the name of the currently active database.
sourceraw docstring

delete!cljmacro

(delete! <collection> <query> & :collation <collation object> :hint {})

Delete matching documents.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
:collationoptional collation object Collation used.
:hintoptional map Indexing hint.

Returns

{:deleted-count <number of matching documents>}
Delete matching documents.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `:collation` | `optional collation object` Collation used.
| `:hint`      | `optional map` Indexing hint.

**Returns**

```clojure
{:deleted-count <number of matching documents>}
```
sourceraw docstring

delete-by-id!clj

(delete-by-id! coll id & options)
source

delete-file!cljmacro

(delete-file! id)
(delete-file! bucket id)
source

delete-one!clj

(delete-one! <collection> <query> & :collation <collation object> :hint {})

Delete first matching document.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
:collationoptional collation object Collation used.
:hintoptional map Indexing hint.

Returns

{:deleted-count <0 or 1>}
Delete first matching document.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `:collation` | `optional collation object` Collation used.
| `:hint`      | `optional map` Indexing hint.

**Returns**

```clojure
{:deleted-count <0 or 1>}
```
sourceraw docstring

distinctcljmacro

(distinct <collection> <field>)
(distinct <collection> <field> <query> & :validate? <boolean>)

Fetch distinct values from a particular field.

ParameterDescription
collectionkeyword/string The collection.
fieldkeyword/string A field in the collection.
querymap A standard MongoDB query.
:validate?optional boolean The field must be part of the collection schema. Default false.

Returns

A lazy sequence of distinct values.

Examples

(insert! :coll-1 [{:a 1} {:a 1} {:a 2}])
(distinct :coll-1 :a) ; Returns [1 2]
(distinct :coll-1 :b) ; Returns []

(create-collection! :coll-2 :schema {:a (map {:b (integer)})})
(insert! :coll-2 [{:a {:b 1}} {:a {:b 2}}])
(distinct :coll-2 :a.b {} :validate? true) ; Returns [1 2]
(distinct :coll-2 :a.a {} :validate? true) ; Returns IllegalArgumentException
Fetch distinct values from a particular field.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `field`      | `keyword/string` A field in the collection.
| `query`      | `map` A standard MongoDB query.
| `:validate?` | `optional boolean` The field must be part of the collection schema. Default false.

**Returns**

A lazy sequence of distinct values.

**Examples**

```clojure
(insert! :coll-1 [{:a 1} {:a 1} {:a 2}])
(distinct :coll-1 :a) ; Returns [1 2]
(distinct :coll-1 :b) ; Returns []

(create-collection! :coll-2 :schema {:a (map {:b (integer)})})
(insert! :coll-2 [{:a {:b 1}} {:a {:b 2}}])
(distinct :coll-2 :a.b {} :validate? true) ; Returns [1 2]
(distinct :coll-2 :a.a {} :validate? true) ; Returns IllegalArgumentException
```
sourceraw docstring

download-filecljmacro

(download-file bucket file & {:as options})
source

drop-collection!clj

(drop-collection! coll)
source

drop-index!clj

(drop-index! coll index)
source

fetchcljmacro

(fetch <collection>)
(fetch <collection>
       <query>
       &
       :collation
       <collation
       object>
       :limit <count>
       :only {}
       :skip <count>
       :sort {})

Fetch documents from collection.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
:collationoptional collation object Collation used.
:limitoptional integer Number of documents to fetch.
:onlyoptional map/list A map/list of fields to include or exclude.
:skipoptional integer Number of documents to skip before fetching.
:sortoptional map A MongoDB map of sorting criteria.

Returns

A lazy sequence of matching documents.

Examples

; Fetch five documents from collection :users
(fetch :users {} :limit 5)
Fetch documents from collection.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `:collation` | `optional collation object` Collation used.
| `:limit`     | `optional integer` Number of documents to fetch.
| `:only`      | `optional map/list` A map/list of fields to include or exclude.
| `:skip`      | `optional integer` Number of documents to skip before fetching.
| `:sort`      | `optional map` A MongoDB map of sorting criteria.

**Returns**

A lazy sequence of matching documents.

**Examples**

```clojure
; Fetch five documents from collection :users
(fetch :users {} :limit 5)
```
sourceraw docstring

fetch-and-delete-by-id!clj

(fetch-and-delete-by-id! coll id & options)
source

fetch-and-delete-one!clj

(fetch-and-delete-one! coll query & options)
source

fetch-and-replace-by-id!cljmacro

(fetch-and-replace-by-id! coll id doc & {:as options})
source

fetch-and-replace-one!cljmacro

(fetch-and-replace-one! coll query doc & {:as options})
source

fetch-and-set-by-id!cljmacro

(fetch-and-set-by-id! coll id update & {:as options})
source

fetch-and-set-one!cljmacro

(fetch-and-set-one! coll query update & {:as options})

Shorthand for fetch-and-update-one! with a single :$set modifier.

Examples

(fetch-and-set-one! :coll {} {:a 1})

translates to:

(fetch-and-update-one! :coll {} {:$set {:a 1}})
Shorthand for `fetch-and-update-one!` with a single `:$set` modifier.

**Examples**

```clojure
(fetch-and-set-one! :coll {} {:a 1})
```
translates to: 
```clojure
(fetch-and-update-one! :coll {} {:$set {:a 1}})
```
sourceraw docstring

fetch-and-update-by-id!clj

(fetch-and-update-by-id! coll id update & {:as options})
source

fetch-and-update-one!cljmacro

(fetch-and-update-one! <collection>
                       <query>
                       &
                       :return-new?
                       <boolean>
                       :upsert?
                       <boolean>
                       :collation
                       <collation
                       object>
                       :only {}
                       :hint {}
                       :sort {})

Update first matching document.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
:return-new?optional boolean Return the updated document? Default if false.
:upsert?optional boolean If no document is found, create a new one. Default is false.
:collationoptional collation object Collation used.
:onlyoptional map A MongoDB map of fields to include or exclude.
:hintoptional map Indexing hint.
:sortoptional map A MongoDB map of sorting criteria.

Returns

A single document or nil.

Update first matching document.

| Parameter      | Description
| ---            | ---
| `collection`   | `keyword/string` The collection.
| `query`        | `map` A standard MongoDB query.
| `:return-new?` | `optional boolean` Return the updated document? Default if `false`.
| `:upsert?`     | `optional boolean` If no document is found, create a new one. Default is `false`.
| `:collation`   | `optional collation object` Collation used.
| `:only`        | `optional map` A MongoDB map of fields to include or exclude.
| `:hint`        | `optional map` Indexing hint.
| `:sort`        | `optional map` A MongoDB map of sorting criteria.

**Returns**

A single document or nil.
sourceraw docstring

fetch-by-idcljmacro

(fetch-by-id <collection> <id> & :only {})

Fetch a single document by its id.

ParameterDescription
collectionkeyword/string The collection.
idObjectId/string The id.
:onlyoptional map A MongoDB map of fields to include or exclude.

Returns

A single document or nil.

Fetch a single document by its id.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `id`         | `ObjectId/string` The id.
| `:only`      | `optional map` A MongoDB map of fields to include or exclude.

**Returns**

A single document or `nil`.
sourceraw docstring

fetch-countclj

(fetch-count <collection>)
(fetch-count <collection> <query>)

Count the number of documents returned.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.

Returns

Number of matching documents.

Count the number of documents returned.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.

**Returns**

Number of matching documents.
sourceraw docstring

fetch-onecljmacro

(fetch-one <collection>)
(fetch-one <collection>
           <query>
           &
           :collation
           <collation
           object>
           :only {}
           :skip <count>
           :sort {})

Return only the first document retrieved.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
:collationoptional collation object Collation used.
:onlyoptional map A MongoDB map of fields to include or exclude.
:skipoptional integer Number of documents to skip before fetching.
:sortoptional map A MongoDB map of sorting criteria.

Returns

A single document or nil.

Return only the first document retrieved.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `:collation` | `optional collation object` Collation used.
| `:only`      | `optional map` A MongoDB map of fields to include or exclude.
| `:skip`      | `optional integer` Number of documents to skip before fetching.
| `:sort`      | `optional map` A MongoDB map of sorting criteria.

**Returns**

A single document or `nil`.
sourceraw docstring

file-infocljmacro

(file-info)
(file-info <bucket>)
(file-info <bucket>
           <query>
           &
           :collation
           <collation
           object>
           :limit <count>
           :only {}
           :skip <count>
           :sort {})

Fetch files.

ParameterDescription
bucketkeyword/string/nil The bucket name. Can be nil to get the default database bucket.
querymap A standard MongoDB query.
:collationoptional collation object Collation used.
:limitoptional integer Number of documents to fetch.
:skipoptional integer Number of documents to skip before fetching.
:sortoptional map/list A map/list of sorting criteria.

Returns

A lazy sequence of matching documents.

Fetch files.

| Parameter    | Description
| ---          | ---
| `bucket`     | `keyword/string/nil` The bucket name. Can be nil to get the default database bucket.
| `query`      | `map` A standard MongoDB query.
| `:collation` | `optional collation object` Collation used.
| `:limit`     | `optional integer` Number of documents to fetch.
| `:skip`      | `optional integer` Number of documents to skip before fetching.
| `:sort`      | `optional map/list` A map/list of sorting criteria.

**Returns**

A lazy sequence of matching documents.
sourceraw docstring

insert!cljmacro

(insert! <collection> <document>)
(insert! <collection> <document-list>)

Insert one document or a list thereof in a collection. Inserting a list is atomic.

ParameterDescription
collectionkeyword/string The collection.
documentmap A document.
document-listlist(map) A list of documents.

Returns

The document/s with _id fields, either a single document or a lazy sequence.

Examples

(insert! :users {:name "Alice"})

(insert! :users [{:name "Alice"} {:name "Bob"}])
Insert one document or a list thereof in a collection.
Inserting a list is atomic.

| Parameter       | Description
| ---             | ---
| `collection`    | `keyword/string` The collection.
| `document`      | `map` A document.
| `document-list` | `list(map)` A list of documents.

**Returns**

The document/s with `_id` fields, either a single document or a lazy sequence.

**Examples**

```clojure
(insert! :users {:name "Alice"})

(insert! :users [{:name "Alice"} {:name "Bob"}])
```
sourceraw docstring

insert-one!cljmacro

(insert-one! 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

list-collection-namesclj

(list-collection-names)

List keyworded names of all collections in database.

List keyworded names of all collections in database.
sourceraw docstring

list-collectionsclj

(list-collections)

List full info of all collections in database.

List full info of all collections in database.
sourceraw docstring

list-databasesclj

(list-databases)

List databases for this connection.

Returns

A lazy sequence of database objects.

List databases for this connection.

**Returns**

A lazy sequence of database objects.
sourceraw docstring

list-indexesclj

(list-indexes coll)
source

modify-collection!cljmacro

(modify-collection! <name>
                    &
                    :collation
                    <collation
                    object>
                    :level [:strict :moderate :off]
                    :schema {}
                    :validation {})

Make updates to a collection.

ParameterDescription
namekeyword/string Collection name.
:nameoptional keyword/string New name.
:collationoptional collation object The collation of the collection.
:schemaoptional map The schema validation map.
:validationoptional map Validation logic outside of the schema.
:leveloptional keyword enum Validaton level:
:strict Apply validation rules to all inserts and all updates. Default value.
:moderate Applies validation rules to inserts and to updates on existing valid documents.
:off No validation for inserts or updates.
:validate?optional boolean Ensure that existing documents in the collection conform to the new schema or validation. Default false.

Returns

The collection object.

Examples

(modify-collection! :coll :name :coll-2)
Make updates to a collection.

| Parameter     | Description
| ---           | ---
| `name`        | `keyword/string` Collection name.
| `:name`       | `optional keyword/string` New name.
| `:collation`  | `optional collation object` The collation of the collection.
| `:schema`     | `optional map` The schema validation map.
| `:validation` | `optional map` Validation logic outside of the schema.
| `:level`      | `optional keyword enum` Validaton level:
|               | `:strict` Apply validation rules to all inserts and all updates. Default value.
|               | `:moderate` Applies validation rules to inserts and to updates on existing valid documents.
|               | `:off` No validation for inserts or updates.
| `:validate?`  | `optional boolean` Ensure that existing documents in the collection conform to the new schema or validation. Default `false`.

**Returns**

The collection object.

**Examples**

```clojure
(modify-collection! :coll :name :coll-2)
```
sourceraw docstring

replace-by-id!cljmacro

(replace-by-id! coll id doc & {:as options})
source

replace-one!cljmacro

(replace-one! <collection>
              <query>
              <document>
              &
              :upsert?
              <boolean>
              :collation
              <collation
              object>
              :hint
              {})

Replace a single document.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
documentmap The new document.
:upsert?optional boolean If no document is found, create a new one. Default is false.
:collationoptional collation object Collation used.
:hintoptional map Indexing hint.

Returns

{:matched-count <0 or 1>
 :modified-count <0 or 1>}
Replace a single document.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `document`   | `map` The new document.
| `:upsert?`   | `optional boolean` If no document is found, create a new one. Default is `false`.
| `:collation` | `optional collation object` Collation used.
| `:hint`      | `optional map` Indexing hint.

**Returns**

```clojure
{:matched-count <0 or 1>
 :modified-count <0 or 1>}
```
sourceraw docstring

set!cljmacro

(set! coll query update & {:as options})

Shorthand for update! with a single :$set modifier.

Examples

(set! :coll {} {:a 1})

translates to:

(update! :coll {} {:$set {:a 1}})
Shorthand for `update!` with a single `:$set` modifier.
 
 **Examples**

```clojure
(set! :coll {} {:a 1})
```
translates to: 
```clojure
(update! :coll {} {:$set {:a 1}})
```
sourceraw docstring

set-by-id!cljmacro

(set-by-id! coll id update & {:as options})
source

set-one!cljmacro

(set-one! coll query update & {:as options})

Shorthand for update-one! with a single :$set modifier.

Examples

(set-one! :coll {} {:a 1})

translates to:

(update-one! :coll {} {:$set {:a 1}})
Shorthand for `update-one!` with a single `:$set` modifier.
 
 **Examples**

```clojure
(set-one! :coll {} {:a 1})
```
translates to: 
```clojure
(update-one! :coll {} {:$set {:a 1}})
```
sourceraw docstring

transactioncljmacro

(transaction)

Functionally perform a transaction. Encapsulated database requests are queued and then atomically executed when the function goes out of scope.

Returns

The result of the last encapsulated expression.

Examples

(transaction
  (insert! :users {:name "My Name"})
  (fetch! :users))
Functionally perform a transaction.
Encapsulated database requests are queued and then atomically executed when the function goes out of scope.

**Returns**

The result of the last encapsulated expression.

**Examples**

```clojure
(transaction
  (insert! :users {:name "My Name"})
  (fetch! :users))
```
sourceraw docstring

update!cljmacro

(update! <collection>
         <query>
         <update>
         &
         :upsert?
         <boolean>
         :collation
         <collation
         object>
         :hint
         {})

Update matching documents.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
updatemap A valid update document.
:upsert?optional boolean If no document is found, create a new one. Default is false.
:collationoptional collation object Collation used.
:hintoptional map/list Indexing hint.

Returns

{:matched-count <number of matching documents>
 :modified-count <number of modified documents>}

Examples

(update!)
Update matching documents.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `update`     | `map` A valid update document.
| `:upsert?`   | `optional boolean` If no document is found, create a new one. Default is `false`.
| `:collation` | `optional collation object` Collation used.
| `:hint`      | `optional map/list` Indexing hint.

**Returns**

```clojure
{:matched-count <number of matching documents>
 :modified-count <number of modified documents>}
```

**Examples**

```clojure
(update!)
```
sourceraw docstring

update-by-id!cljmacro

(update-by-id! coll id update & {:as options})
source

update-one!cljmacro

(update-one! <collection>
             <query>
             <update>
             &
             :upsert?
             <boolean>
             :collation
             <collation
             object>
             :hint {}
             :write-concern [:acknowledged :unacknowledged :journaled :majority
                             :w1 :w2 :w3])

Update first matching document.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
updatemap/list A valid update document or pipeline.
:upsert?optional boolean If no document is found, create a new one. Default is false.
:collationoptional collation object Collation used.
:hintoptional map/list Indexing hint.

Returns

{:matched-count <0 or 1>
 :modified-count <0 or 1>}

Examples

(update-one!)
Update first matching document.

| Parameter    | Description
| ---          | ---
| `collection` | `keyword/string` The collection.
| `query`      | `map` A standard MongoDB query.
| `update`     | `map/list` A valid update document or pipeline.
| `:upsert?`   | `optional boolean` If no document is found, create a new one. Default is `false`.
| `:collation` | `optional collation object` Collation used.
| `:hint`      | `optional map/list` Indexing hint.

**Returns**

```clojure
{:matched-count <0 or 1>
 :modified-count <0 or 1>}
```

**Examples**

```clojure
(update-one!)
```
sourceraw docstring

upload-file!cljmacro

(upload-file! bucket file & {:as options})
source

with-codecscljmacro

(with-codecs <codecs> <bson-types> & <body>)

Add or change codecs. Reverts to earlier settings when leaving scope.

ParameterDescription
codecslist A list of codec objects.
bson-typesmap A map of Bson types and their corresponding Java classes.
bodyEncapsulated program calling the database.

Returns

Example

Add or change codecs.
Reverts to earlier settings when leaving scope.

| Parameter    | Description
| ---          | ---
| `codecs`     | `list` A list of codec objects.
| `bson-types` | `map` A map of Bson types and their corresponding Java classes.
| `body`       | Encapsulated program calling the database.

**Returns**

**Example**
sourceraw docstring

with-databasecljmacro

(with-database <database> & <body>)

Functionally set up or change database. Reverts to earlier settings when leaving scope.

ParameterDescription
databasestring Name of database to use.
bodyEncapsulated program calling the database.

Returns

The result of the last encapsulated expression.

Examples

(with-database "my-database-2"
  (insert! :users {:name "My Name"})
  (fetch! :users))
Functionally set up or change database.
Reverts to earlier settings when leaving scope.

| Parameter  | Description
| ---        | ---
| `database` | `string` Name of database to use.
| `body`     | Encapsulated program calling the database.

**Returns**

The result of the last encapsulated expression.

**Examples**

```clojure
(with-database "my-database-2"
  (insert! :users {:name "My Name"})
  (fetch! :users))
```
sourceraw docstring

with-mongocljmacro

(with-mongo <uri> & <body>)
(with-mongo <connection> & <body>)

Functionally set up or change mongodb connection. Reverts to earlier settings when leaving scope.

ParameterDescription
uristring Connection string. See the API documentation for more details.
connectionconnection A connection object.
bodyEncapsulated program utilizing the connection.

Returns

The result of the last encapsulated expression.

Examples

(with-mongo "mongodb://localhost:27017/my-database"
  (insert! :users {:name "My Name"})
  (fetch! :users))
Functionally set up or change mongodb connection.
Reverts to earlier settings when leaving scope.

| Parameter    | Description
| ---          | ---
| `uri`        | `string` Connection string. See the [API documentation](http://mongodb.github.io/mongo-java-driver/4.5/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html) for more details.
| `connection` | `connection` A connection object.
| `body`       | Encapsulated program utilizing the connection.

**Returns**

The result of the last encapsulated expression.

**Examples**

```clojure
(with-mongo "mongodb://localhost:27017/my-database"
  (insert! :users {:name "My Name"})
  (fetch! :users))
```
sourceraw docstring

with-read-concerncljmacro

(with-read-concern <read-concern> & <body>)

Set read concern of current active database. Reverts to earlier settings when leaving scope.

ParameterDescription
: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.
Set read concern of current active database.
Reverts to earlier settings when leaving scope.

| Parameter        | Description
| ---              | ---
| `: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/).
sourceraw docstring

with-write-concerncljmacro

(with-write-concern <write-concern> & <body>)

Set write concern of current active database. Reverts to earlier settings when leaving scope.

ParameterDescription
: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 write concern of current active database.
Reverts to earlier settings when leaving scope.

| Parameter        | Description
| ---              | ---
| `: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

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

× close