Liking cljdoc? Tell your friends :D

com.timezynk.mongo


aggregateclj

(aggregate collection pipeline)

MongoDB aggregation.

ParameterDescription
collectionkeyword/string Collection name.
pipelinelist {keyword/string {}} A list containing the request pipeline documents.

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`   | `list {keyword/string {}}` A list containing the request pipeline documents. |

**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. Default false.
: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. Default `false`. |
| `: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 <number of matching documents>}
Delete first matching document.

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

**Returns**

```Clojure
{:deleted-count <number of matching documents>}
```
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.
query{keyword/string object} A standard MongoDB query.
:limitoptional int Number of documents to fetch.
:onlyoptional {keyword/string object} A MongoDB map of fields to include or exclude.
:skipoptional int Number of documents to skip before fetching.
:sortoptional {keyword/string object} 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`      | `{keyword/string object}` A standard MongoDB query. |
| `:limit`     | `optional int` Number of documents to fetch. |
| `:only`      | `optional {keyword/string object}` A MongoDB map of fields to include or exclude. |
| `:skip`      | `optional int` Number of documents to skip before fetching. |
| `:sort`      | `optional {keyword/string object}` 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.
query{keyword/string object} A standard MongoDB query.

Returns

Number of matching documents.

Count the number of documents returned.

| Parameter    | Description |
| ---          | --- |
| `collection` | `keyword/string` The collection. |
| `query`      | `{keyword/string object}` 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.
query{keyword/string object} A standard MongoDB query.

Returns

A single document or nil.

Return only the first document retrieved.

| Parameter    | Description |
| ---          | --- |
| `collection` | `keyword/string` The collection. |
| `query`      | `{keyword/string object}` 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.
document/smap/list(map) A document or 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/s` | `map/list(map)` A document or 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

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

(set-connection! uri)

Procedurally set up or change mongodb connection.

uri - string: database location.

Procedurally set up or change mongodb connection.

uri - string: database location.
sourceraw docstring

set-database!clj

(set-database! db)

Procedurally set up or change database.

db - string: name of database to use.

Procedurally set up or change database.

db - string: name of database to use.
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.
query{keyword/string object} A standard MongoDB query.
update{keyword/string object} 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`      | `{keyword/string object}` A standard MongoDB query. |
| `update`     | `{keyword/string object}` 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.
query{keyword/string object} A standard MongoDB query.
update{keyword/string object} A valid update document. Must use $set or $push.
: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`      | `{keyword/string object}` A standard MongoDB query. |
| `update`     | `{keyword/string object}` A valid update document. Must use $set or $push. |
| `: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)

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

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