Liking cljdoc? Tell your friends :D

mongo-driver-3.client


*session*clj

source

->ClientSessionOptionsclj

(->ClientSessionOptions {:keys [client-session-options causally-consistent?]
                         :as opts})

Coerces an options map into a ClientSessionOptions See start-session for usage.

See start-session for usage

Coerces an options map into a ClientSessionOptions See `start-session` for usage.

See `start-session` for usage
sourceraw docstring

->TransactionOptionsclj

(->TransactionOptions {:keys [max-commit-time-ms] :as opts})

Coerces options map into a TransactionOptions. See start-session for usage.

Coerces options map into a TransactionOptions. See `start-session` for usage.
sourceraw docstring

closeclj

(close client)

Close a MongoClient and release all resources

Close a MongoClient and release all resources
sourceraw docstring

connect-to-dbclj

(connect-to-db connection-string)

Connects to a MongoDB database using a URI, returning the client and database as a map with :client and :db.

This is useful to get a db from a single call, instead of having to create a client and get a db manually.

Connects to a MongoDB database using a URI, returning the client and database as a map with :client and :db.

This is useful to get a db from a single call, instead of having to create a client and get a db manually.
sourceraw docstring

createclj

(create)
(create connection-string)

Creates a connection to a MongoDB

connection-string is a mongo connection string, e.g. mongodb://localhost:27107

If a connecting string is not passed in, it will connect to the default localhost instance.

Creates a connection to a MongoDB

`connection-string` is a mongo connection string, e.g. mongodb://localhost:27107

If a connecting string is not passed in, it will connect to the default localhost instance.
sourceraw docstring

get-dbclj

(get-db client name)

Gets a database by name

client is a MongoClient, e.g. resulting from calling connect name is the name of the database to get.

Gets a database by name

`client` is a MongoClient, e.g. resulting from calling `connect`
`name` is the name of the database to get.
sourceraw docstring

list-collection-namesclj

(list-collection-names db)
(list-collection-names db opts)

Lists collection names in a database, returning as a seq of strings unless otherwise configured.

Arguments:

  • db a MongoDatabase
  • opts (optional), a map of:
    • :raw? return the mongo MongoIterable directly instead of processing into a seq, default: false
    • :session a ClientSession
Lists collection names in a database, returning as a seq of strings unless otherwise configured.

Arguments:

- `db` a MongoDatabase
- `opts` (optional), a map of:
  - `:raw?` return the mongo MongoIterable directly instead of processing into a seq, default: false
  - `:session` a ClientSession
sourceraw docstring

list-collectionsclj

(list-collections db)
(list-collections db
                  {:keys [raw? keywordize? session realise-fn]
                   :or {keywordize? true realise-fn sequence}})

Lists collections in a database, returning as a seq of maps unless otherwise configured.

Arguments:

  • db a MongoDatabase
  • opts (optional), a map of:
    • :name-only? returns just the string names
    • :keywordize? keywordize the keys of return results, default: true. Only applicable if :name-only? is false.
    • :raw? return the mongo iterable directly instead of processing into a clj data-structure, default: false
    • :realise-fn how to realise the MongoIterable, default: clojure.core/sequence (i.e. lazily)
    • :session a ClientSession
Lists collections in a database, returning as a seq of maps unless otherwise configured.

Arguments:

- `db` a MongoDatabase
- `opts` (optional), a map of:
  - `:name-only?` returns just the string names
  - `:keywordize?` keywordize the keys of return results, default: true. Only applicable if `:name-only?` is false.
  - `:raw?` return the mongo iterable directly instead of processing into a clj data-structure, default: false
  - `:realise-fn` how to realise the MongoIterable, default: `clojure.core/sequence` (i.e. lazily)
  - `:session` a ClientSession
sourceraw docstring

start-sessionclj

(start-session client)
(start-session client opts)

Creates a client session.

Arguments:

  • client a MongoClient
  • opts (optional), a map of:
    • :max-commit-time-ms Max execution time for commitTransaction operation, in milliseconds
    • :causally-consistent? whether operations using session should be causally consistent with each other
    • :read-preference Accepts a ReadPreference or a kw corresponding to one: [:primary, :primaryPreferred, :secondary, :secondaryPreferred, :nearest] Invalid values will throw an exception.
    • :read-concern Accepts a ReadConcern or kw corresponding to one: [:available, :default, :linearizable, :local, :majority, :snapshot] Invalid values will throw an exception.
    • :write-concern A WriteConcern or kw corresponding to one: [:acknowledged, :journaled, :majority, :unacknowledged, :w1, :w2, :w3], defaulting to :acknowledged, if some invalid option is provided.
    • :write-concern/w an int >= 0, controlling the number of replicas to acknowledge
    • :write-concern/w-timeout-ms How long to wait for secondaries to acknowledge before failing, in milliseconds (0 means indefinite).
    • :write-concern/journal? If true, block until write operations have been committed to the journal.
    • :client-session-options a ClientSessionOptions, for configuring directly. If specified, any other [preceding] query options will be applied to it.
Creates a client session.

Arguments:

- `client` a MongoClient
- `opts` (optional), a map of:
  - `:max-commit-time-ms` Max execution time for commitTransaction operation, in milliseconds
  - `:causally-consistent?` whether operations using session should be causally consistent with each other
  - `:read-preference` Accepts a ReadPreference or a kw corresponding to one:
     [:primary, :primaryPreferred, :secondary, :secondaryPreferred, :nearest]
     Invalid values will throw an exception.
  - `:read-concern` Accepts a ReadConcern or kw corresponding to one:
    [:available, :default, :linearizable, :local, :majority, :snapshot]
    Invalid values will throw an exception.
  - `:write-concern` A WriteConcern or kw corresponding to one:
    [:acknowledged, :journaled, :majority, :unacknowledged, :w1, :w2, :w3],
    defaulting to :acknowledged, if some invalid option is provided.
  - `:write-concern/w` an int >= 0, controlling the number of replicas to acknowledge
  - `:write-concern/w-timeout-ms` How long to wait for secondaries to acknowledge before failing,
    in milliseconds (0 means indefinite).
  - `:write-concern/journal?` If true, block until write operations have been committed to the journal.
  - `:client-session-options` a ClientSessionOptions, for configuring directly. If specified, any
    other [preceding] query options will be applied to it.
sourceraw docstring

with-implicit-transactionclj

(with-implicit-transaction {:keys [client transaction-opts session-opts]
                            :or {transaction-opts {} session-opts {}}}
                           body)

Automatically sets the session / transaction for all mongo operations within the scope, using a dynamic binding.

The first argument is an options map with keys:

  • :client a MongoClient (mandatory)
  • :transaction-opts (see ->TransactionOptions for keys)
  • :session-opts (see start-session for details)

The second argument body is a fn with one or more mongo operations in it. e.g.

(mg/with-implicit-transaction
  {:client client}
  (fn []
    (mc/insert-one my-db "coll" {:name "hello"})
    (mc/insert-one my-db "coll" {:name "world"})))
Automatically sets the session / transaction for all mongo operations
within the scope, using a dynamic binding.

The first argument is an options map with keys:

- `:client` a MongoClient (mandatory)
- `:transaction-opts` (see `->TransactionOptions` for keys)
- `:session-opts` (see `start-session` for details)

The second argument `body` is a fn with one or more mongo operations in it.
e.g.

```
(mg/with-implicit-transaction
  {:client client}
  (fn []
    (mc/insert-one my-db "coll" {:name "hello"})
    (mc/insert-one my-db "coll" {:name "world"})))
```
sourceraw docstring

with-transactionclj

(with-transaction session body)
(with-transaction session body opts)

Executes body in a transaction.

body should be a fn with one or more mongo operations in it. Ensure session is passed as an option to each operation.

e.g.

(with-open [s (start-session client)]
  (with-transaction s
    (fn []
      (insert-one my-db "coll" {:name "hello"} {:session s})
      (insert-one my-db "coll" {:name "world"} {:session s}))))
Executes `body` in a transaction.

`body` should be a fn with one or more mongo operations in it.
Ensure `session` is passed as an option to each operation.

e.g.

```clojure
(with-open [s (start-session client)]
  (with-transaction s
    (fn []
      (insert-one my-db "coll" {:name "hello"} {:session s})
      (insert-one my-db "coll" {:name "world"} {:session s}))))
```
sourceraw docstring

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

× close