Liking cljdoc? Tell your friends :D

com.timezynk.mongo


aggregateclj

(aggregate collection pipeline)

MongoDB aggregation.

parameterdescription
collectionkeyword/string Collection name.
pipelinelist {keyword/string {}}
(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. |

```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! coll keys & options)

Create an index for a collection. coll - keyword/string: Collection name. keys - map/list(keyword/string): A document or a list of keywords or strings. Optional parameters: background - boolean: Create the index in the background. name - string: A custom name for the index. partial-filter-expression - map: A filter expression for the index. sparse - boolean: Allow null values. unique - boolean: Index values must be unique.

Create an index for a collection.
coll - keyword/string: Collection name.
keys - map/list(keyword/string): A document or a list of keywords or strings.
Optional parameters:
  background                - boolean: Create the index in the background.
  name                      - string: A custom name for the index.
  partial-filter-expression - map: A filter expression for the index.
  sparse                    - boolean: Allow null values.
  unique                    - boolean: Index values must be unique.
sourceraw docstring

delete!clj

(delete! coll query & options)

Delete matching documents. coll - keyword/string: The collection. query - map: A standard MongoDB query. Optional parameters: None yet.

Delete matching documents.
coll  - keyword/string: The collection.
query - map: A standard MongoDB query.
Optional parameters:
  None yet.
sourceraw docstring

delete-one!clj

(delete-one! coll query & options)

Delete first matching document. coll - keyword/string: The collection. query - map: A standard MongoDB query. Optional parameters: None yet.

Delete first matching document.
coll  - keyword/string: The collection.
query - map: A standard MongoDB query.
Optional parameters:
  None yet.
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.
; 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. |

```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! coll query update & options)
source

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.
Count the number of documents returned.

| parameter | description |
| --- | --- |
| `collection` | `keyword/string` The collection. |
| `query` | `{keyword/string object}` A standard MongoDB query. |
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.
Return only the first document retrieved.

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

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

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

list-indexesclj

(list-indexes coll)
source

replace-one!clj

(replace-one! coll query doc & options)

Replace a single document. coll - keyword/string: The collection. query - map: A standard MongoDB query. doc - map: The new document. Optional parameters: upsert? - boolean: If no document is found, create a new one. Default is don't create.

Replace a single document.
coll  - keyword/string: The collection.
query - map: A standard MongoDB query.
doc   - map: The new document.
Optional parameters:
  upsert? - boolean: If no document is found, create a new one. Default is don't create.
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.

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

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

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


| Examples |
| ---      |
| ```Clojure
(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.
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`. |
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.
(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. |

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

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