Liking cljdoc? Tell your friends :D

com.timezynk.mongo


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

create-collection!clj

(create-collection! name)
source

create-index!clj

(create-index! collection
               keys
               &
               :background b
               :name s
               :partial-filter-expression {}
               :sparse b
               :unique b)

Create an index for a collection.

ParameterDescription
collectionkeyword/string Collection name.
keysmap/list(keyword/string) A document or a list of keywords or strings.
:backgroundoptional boolean Create the index in the background. Default false.
:nameoptional string A custom name for the index.
:partial-filter-expressionoptional map A filter expression for the index.
:sparseoptional boolean Allow null values. Default false.
:uniqueoptional boolean Index values must be unique. Default false.

Returns

The index name.

Examples

(create-index!)
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. |
| `:background`                | `optional boolean` Create the index in the background. Default `false`. |
| `:name`                      | `optional string` A custom name for the index. |
| `:partial-filter-expression` | `optional map` A filter expression for the index. |
| `:sparse`                    | `optional boolean` Allow null values. Default `false`. |
| `:unique`                    | `optional boolean` Index values must be unique. Default `false`. |

**Returns**

The index name.

**Examples**

```Clojure
(create-index!)
```
sourceraw docstring

delete!clj

(delete! collection query)

Delete matching documents.

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

Returns

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

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

**Returns**

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

delete-one!clj

(delete-one! collection query)

Delete first matching document.

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

Returns

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

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

**Returns**

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

drop-collection!clj

(drop-collection! coll)
source

drop-index!clj

(drop-index! coll index)
source

fetchclj

(fetch collection)
(fetch collection query & :limit n :only {} :skip n :sort {})

Fetch documents from collection.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
:limitoptional int Number of documents to fetch.
:onlyoptional map A MongoDB map of fields to include or exclude.
:skipoptional int 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. |
| `:limit`     | `optional int` Number of documents to fetch. |
| `:only`      | `optional map` A MongoDB map of fields to include or exclude. |
| `:skip`      | `optional int` 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!clj

(fetch-and-delete! coll query)
source

fetch-and-replace!clj

(fetch-and-replace! coll query doc & options)
source

fetch-and-update!clj

(fetch-and-update! collection query & :return-new? b :upsert? b)

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.

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

**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-oneclj

(fetch-one collection)
(fetch-one collection query)

Return only the first document retrieved.

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

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

**Returns**

A single document or `nil`.
sourceraw docstring

get-collectionsclj

(get-collections)
source

insert!clj

(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

list-indexesclj

(list-indexes coll)
source

make-connectionclj

(make-connection uri & :retry-writes b :write-concern o)

Create a connection object.

ParameterDescription
uristring Database location.
:retry-writesoptional boolean Sets whether writes should be retried if they fail due to a network error. Default is false.
:write-concernoptional atom Set write concern:
:acknowledged Write operations that use this write concern will wait for acknowledgement. Default.
:unacknowledged Write operations that use this write concern will return as soon as the message is written to the socket.
:majority Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation.
:w1 Write operations that use this write concern will wait for acknowledgement from a single member.
:w2 Write operations that use this write concern will wait for acknowledgement from two members.
:w3 Write operations that use this write concern will wait for acknowledgement from three members.

Returns

The connection object.

Examples

; Create a connection with default options
(make-connection "mongodb://localhost:27017")

; Create a custom connection
(make-connection "mongodb://localhost:27017" :retry-writes true :write-concern :w2)
Create a connection object.

| Parameter        | Description |
| ---              | --- |
| `uri`            | `string` Database location. |
| `:retry-writes`  | `optional boolean` Sets whether writes should be retried if they fail due to a network error. Default is `false`. |
| `:write-concern` | `optional atom` Set write concern: |
|                  | `:acknowledged` Write operations that use this write concern will wait for acknowledgement. Default. |
|                  | `:unacknowledged` Write operations that use this write concern will return as soon as the message is written to the socket. |
|                  | `:majority` Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation. |
|                  | `:w1` Write operations that use this write concern will wait for acknowledgement from a single member. |
|                  | `:w2` Write operations that use this write concern will wait for acknowledgement from two members. |
|                  | `:w3` Write operations that use this write concern will wait for acknowledgement from three members. |

**Returns**

The connection object.

**Examples**

```Clojure
; Create a connection with default options
(make-connection "mongodb://localhost:27017")

; Create a custom connection
(make-connection "mongodb://localhost:27017" :retry-writes true :write-concern :w2)
```
sourceraw docstring

replace-one!clj

(replace-one! collection query document & :upsert? b)

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.

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

**Returns**

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

set-collation!clj

(set-collation! :backwards b
                :case-level b
                :collation-alternate o
                :collation-case-first o
                :collation-max-variable o
                :collation-strength o
                :locale s
                :normalization b
                :numeric-ordering b)

Set collation for this thread.

ParameterDescription
:backwardsoptional boolean
:case-leveloptional boolean
:collation-alternate'optional atom`
:collation-case-firstoptional atom
:collation-max-variableoptional atom
:collation-strengthoptional atom
:localeoptional string
:normalizationoptional boolean
:numeric-orderingoptional boolean

Returns

Examples

(set-collation!)
Set collation for this thread.

| Parameter                 | Description |
| ---                       | --- |
| `:backwards`              | `optional boolean`  |
| `:case-level`             | `optional boolean`  |
| `:collation-alternate`    | 'optional atom`  |
| `:collation-case-first`   | `optional atom`  |
| `:collation-max-variable` | `optional atom`  |
| `:collation-strength`     | `optional atom`  |
| `:locale`                 | `optional string`  |
| `:normalization`          | `optional boolean`  |
| `:numeric-ordering`       | `optional boolean`  |

**Returns**


**Examples**

```Clojure
(set-collation!)
```
sourceraw docstring

transactioncljmacro

(transaction & body)

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!clj

(update! collection query update & :upsert? b)

Update matching documents.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
updatemap A valid update document. Must use $set or $push, throws exception otherwise.
:upsert?optional boolean If no document is found, create a new one. Default is false.

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. Must use `$set` or `$push`, throws exception otherwise. |
| `:upsert?`   | `optional boolean` If no document is found, create a new one. Default is `false`. |

**Returns**

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

**Examples**

```Clojure
(update!)
```
sourceraw docstring

update-one!clj

(update-one! collection query update & :upsert? b)

Update first matching document.

ParameterDescription
collectionkeyword/string The collection.
querymap A standard MongoDB query.
updatemap A valid update document. Must use $set or $push, throws exception otherwise.
:upsert?optional boolean If no document is found, create a new one. Default is false.

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` A valid update document. Must use `$set` or `$push`, throws exception otherwise. |
| `:upsert?`   | `optional boolean` If no document is found, create a new one. Default is `false`. |

**Returns**

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

**Examples**

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

with-dbcljmacro

(with-db db & body)

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

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

Returns

The result of the last encapsulated expression.

Examples

(with-db "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 |
| ---       | --- |
| `db`      | `string` Name of database to use. |
| `body`    | Encapsulated program calling the database. |

**Returns**

The result of the last encapsulated expression.

**Examples**

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

with-mongocljmacro

(with-mongo uri db & body)
(with-mongo connection db & body)

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

ParameterDescription
uristring Database location.
'connection'A connection object.
dbstring Database to use.
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` Database location. |
| 'connection' | A connection object. |
| `db`         | `string` Database to use. |
| `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

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

× close