A clojure wrapper over the official MongoDB java driver
A clojure wrapper over the official MongoDB java driver
(aggregate db coll bson-pipeline)
Execute an aggregation pipeline on a collection.
Execute an aggregation pipeline on a collection.
(client-session-options {:keys [causally-consistent transaction-opts] :as opts})
Default MongoDB client session options.
Default MongoDB client session options.
(client-settings {{:keys [user-name password source]} :credential
:keys [read-preference read-concern write-concern retry-reads
retry-writes]
:as opts})
Initialize a ConnectionPoolSettings object from given options map. Available options : :read-preference :read-concern :write-concern :retry-reads :retry-writes
Initialize a ConnectionPoolSettings object from given options map. Available options : :read-preference :read-concern :write-concern :retry-reads :retry-writes
(cluster-settings builder {:keys [hosts] :as opts})
Initialize a ClusterSettings object from given options map. Available options : :hosts
Initialize a ClusterSettings object from given options map. Available options : :hosts
(connect :direct {:host host :port port :opts opts})
(connect :replica-set [{:host host :port port :opts opts} & more])
Initialize the MongoDB Connection. Mongo Client Opts, if any, are taken from the first server-spec. Ref. `client-settings' fn for a list of default opts that are applied to the Mongo Client.
Initialize the MongoDB Connection. Mongo Client Opts, if any, are taken from the first server-spec. Ref. `client-settings' fn for a list of default opts that are applied to the Mongo Client.
(connection-pool-settings builder
{:keys [connections-per-host max-connection-wait-time]
:as opts})
Initialize a ConnectionPoolSettings object from given options map. Available options : :connections-per-host :max-connection-wait-time
Initialize a ConnectionPoolSettings object from given options map. Available options : :connections-per-host :max-connection-wait-time
(count-docs db coll query)
(count-docs db session coll query)
Count documents in a collection. Optionally take a query.
Count documents in a collection. Optionally take a query.
(create-index db coll index-spec)
(create-index db session coll index-spec)
(create-index db session coll index-spec options)
Ensure that the given index on the collection exists. Inexpensive if the index already exists. index-spec is map like : {:field 1 :another-field -1} 1 indicates ascending index, -1 indicated descending index To ensure order of the fields in a compound index, always use an array map like : (array-map :field 1 :another-field -1) Supports option :unique (boolean) => creates a unique index
Ensure that the given index on the collection exists. Inexpensive if the index already exists. index-spec is map like : {:field 1 :another-field -1} 1 indicates ascending index, -1 indicated descending index To ensure order of the fields in a compound index, always use an array map like : (array-map :field 1 :another-field -1) Supports option :unique (boolean) => creates a unique index
(delete
db
coll
query
&
{write-concern :write-concern session :session :or {write-concern :majority}})
Delete a document from the collection that matches query
.
wc is the write-concern which should be a key from write-concern-map and is optional.
Else the default write-concern is used.
Delete a document from the collection that matches `query`. wc is the write-concern which should be a key from write-concern-map and is optional. Else the default write-concern is used.
(distinct-vals db
coll
field-name
class-type
filter
&
{:keys [only exclude session] :or {only [] exclude []}})
Gets the distinct values for a field name that matches the filter.
Gets the distinct values for a field name that matches the filter.
(drop-collection db coll)
(drop-collection db session coll)
Drop the given collection.
Drop the given collection.
(drop-database db)
(drop-database db session)
Drop the given database.
Drop the given database.
(fetch-one db
coll
query
&
{:keys [only exclude session] :or {only [] exclude []}})
Fetch a single document depending on query. Optionally return (or exclude) only a subset of the fields.
Fetch a single document depending on query. Optionally return (or exclude) only a subset of the fields.
(get-collection db coll)
(get-collection db coll write-concern)
Get the collection object from given db
Get the collection object from given db
(get-collection-names db)
(get-collection-names db session)
Returns names of all the collections for the given db
Returns names of all the collections for the given db
(get-database-names client)
(get-database-names client session)
Get all database names available in the given mongo server.
Get all database names available in the given mongo server.
(get-databases client)
(get-databases client session)
Get all databases available in the given mongo server.
Get all databases available in the given mongo server.
(get-db client db-name)
Get the database object given a name.
Get the database object given a name.
(get-indexes db coll)
(get-indexes db session coll)
Get indexes for a given collection
Get indexes for a given collection
(insert db
coll
docs
&
{multi? :multi?
write-concern :write-concern
session :session
:or {multi? false write-concern :majority}})
Insert a document into the database. If inserting in bulk, provide a vector of maps and set multi? as true.
Insert a document into the database. If inserting in bulk, provide a vector of maps and set multi? as true.
(query db
coll
query
&
{:keys [sort-by limit only exclude skip one? batch-size session]
:or {skip 0 limit 10 one? false only [] exclude [] batch-size 10000}})
Perform an arbitrary query on a collection. Optionally sort, limit, paginate, fetch a subset of fields. Note: Beware of the queries where limit > batch-size which can lead to a situation where 1 batch is received and processed and if for another batch if mongod server goes down at the same time, then cursor is lost and query will fail with the Cursor exception
Perform an arbitrary query on a collection. Optionally sort, limit, paginate, fetch a subset of fields. Note: Beware of the queries where limit > batch-size which can lead to a situation where 1 batch is received and processed and if for another batch if mongod server goes down at the same time, then cursor is lost and query will fail with the Cursor exception
(run-in-transaction client body-fn {:keys [transaction-opts] :as options})
Execute the given code in a MongoDB transaction.
client
: The MongoClient connection object
body-fn
: The body-fn should be a function which takes 1 argument,
a ClientSession object. This session object needs to be
passed in to all the mongrove APIs which take a session arg.
options
: Currently supported keys are :
transaction-opts
{:read-preference :read-concern :write-concern :retry-on-errors}
If the transaction fails with a retryable error label, and retry-on-errors is true,
mongrove will keep retrying the transaction.
For other options, refer to the MongoDB documentation.
For default values chosen, refer to Jepsen's recommendations
here : http://jepsen.io/analyses/mongodb-4.2.6
Execute the given code in a MongoDB transaction. `client` : The MongoClient connection object `body-fn` : The body-fn should be a function which takes 1 argument, a ClientSession object. This session object needs to be passed in to all the mongrove APIs which take a session arg. `options`: Currently supported keys are : `transaction-opts` {:read-preference :read-concern :write-concern :retry-on-errors} If the transaction fails with a retryable error label, and retry-on-errors is true, mongrove will keep retrying the transaction. For other options, refer to the MongoDB documentation. For default values chosen, refer to Jepsen's recommendations here : http://jepsen.io/analyses/mongodb-4.2.6
(socket-settings builder {:keys [connect-timeout socket-timeout] :as opts})
Initialize a SocketSettings object from given options map. Available options : :connect-timeout :socket-timeout
Initialize a SocketSettings object from given options map. Available options : :connect-timeout :socket-timeout
(transaction-options {:keys [read-preference read-concern write-concern]
:as opts})
Default Transaction options.
Default Transaction options.
(update db
coll
query
doc
&
{upsert? :upsert?
multi? :multi?
write-concern :write-concern
session :session
:or {upsert? false multi? false write-concern :majority}})
Update one or more documents with given document depending on query. Optionally upsert.
Update one or more documents with given document depending on query. Optionally upsert.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close