Murmeli MongoDB driver
Murmeli MongoDB driver [Javadoc](https://www.mongodb.com/docs/drivers/java/sync/current/)
(aggregate! conn collection pipeline & {:as options})
Like aggregate-reducible!
, but eagerly executes the aggregation and returns a vector of documents.
Like [[aggregate-reducible!]], but eagerly executes the aggregation and returns a vector of documents.
(aggregate-reducible! conn collection pipeline & {:as options})
Execute an aggregation pipelien on a collection.
Returns a reducible (IReduceInit),
which can be reduced (using reduce
, into
, transduce
, run!
,...)
to execute the aggregation and produce the resulting documents.
Execute an aggregation pipelien on a collection. Returns a reducible ([IReduceInit](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IReduceInit.java)), which can be reduced (using `reduce`, `into`, `transduce`, `run!`,...) to execute the aggregation and produce the resulting documents.
(connect-client! {:keys [cluster-settings credentials keywords? read-concern
read-preference retry-reads? retry-writes? ssl-settings
uri write-concern]
:as db-spec})
Connects to a Mongo instance as described by the db-spec
by constructing a client connection.
Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespacecluster-settings
-- Map of cluster settings, see belowcredentials
-- Credentials to use, map of auth-db
, username
, and password
keywords?
-- If true, deserialize map keys as keywords instead of stringsread-concern
-- Choose level of read isolation, see murmeli.impl.data-interop/get-read-concern
read-preference
-- Choose preferred replica set members when reading, see murmeli.impl.data-interop/get-read-preference
retry-reads?
-- Retry reads if they fail due to a network errorretry-writes?
-- Retry writes if they fail due to a network errorssl-settings
-- Map of SSL settings, see belowuri
-- The connection string to use, eg. "mongodb://[username:password@]host[:port1],..."write-concern
-- Acknowledgement of write operations, see murmeli.impl.data-interop/get-write-concern
The cluster-settings
map:
hosts
-- Sequence of maps with host
and optionally port
The ssl-settings
map:
enabled?
-- Enable SSLinvalid-hostname-allowed?
-- Allow invalid hostnamesReturns a connection (map).
Connects to a Mongo instance as described by the `db-spec` by constructing a client connection. Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace * `cluster-settings` -- Map of cluster settings, see below * `credentials` -- Credentials to use, map of `auth-db`, `username`, and `password` * `keywords?` -- If true, deserialize map keys as keywords instead of strings * `read-concern` -- Choose level of read isolation, see [[murmeli.impl.data-interop/get-read-concern]] * `read-preference` -- Choose preferred replica set members when reading, see [[murmeli.impl.data-interop/get-read-preference]] * `retry-reads?` -- Retry reads if they fail due to a network error * `retry-writes?` -- Retry writes if they fail due to a network error * `ssl-settings` -- Map of SSL settings, see below * `uri` -- The connection string to use, eg. "mongodb://[username:password@]host[:port1],..." * `write-concern` -- Acknowledgement of write operations, see [[murmeli.impl.data-interop/get-write-concern]] The `cluster-settings` map: * `hosts` -- Sequence of maps with `host` and optionally `port` The `ssl-settings` map: * `enabled?` -- Enable SSL * `invalid-hostname-allowed?` -- Allow invalid hostnames Returns a connection (map).
(connected? conn)
Return true
if the conn
contains a client connection.
Return `true` if the `conn` contains a client connection.
(count-collection conn
collection
&
{:keys [allow-qualified? collation-options comment hint
keywords? limit max-time-ms query sanitize-strings?
skip]})
Count the number of documents in a collection.
Returns the number of documents.
Count the number of documents in a collection. Returns the number of documents.
(create-collection! conn collection)
Creates a collection.
Returns nil
.
Creates a collection. Returns `nil`.
(create-id)
Returns a new unique string representation of an object id.
Returns a new unique string representation of an object id.
(create-index! conn
collection
index-keys
&
{:keys [allow-qualified? background? bits collation-options
default-language expire-after-seconds hidden? index-name
language-override max-boundary min-boundary
partial-filter-expression sanitize-strings? sparse?
sphere-version storage-engine text-version unique?
version weights wildcard-projection]})
Create a new index.
Arguments:
conn
-- The database connectioncollection
-- The collection to operate onindex-keys
-- Map of index name to index type (1, -1, 2d, 2dsphere, text)Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespacebackground?
-- Create index in the backgroundbits
-- 2d index location geodata hash precision bitscollation-options
-- Map of collation options, see murmeli.impl.data-interop/make-collation
default-language
-- Text index languageexpire-after-seconds
-- TTL for removing indexed documentshidden?
-- Hide index from the query plannerlanguage-override
-- Name of the field that contains the language stringmax-boundary
-- Upper inclusive boundary for the longitude and latitude values for 2d indexesmin-boundary
-- Lower inclusive boundary for the longitude and latitude values for 2d indexesindex-name
-- Name of the indexpartial-filter-expression
-- Filter expression (a map) for including documents in the indexsparse?
-- Create a sparse indexsphere-version
-- The 2dsphere index version numberstorage-engine
-- Map of storage engine optionstext-version
-- The text index version numberunique?
-- Create a unique indexversion
-- The index version numberweights
-- Map of text index field weightswildcard-projection
-- Map of fields to include/exclude in a wildcard indexReturns the name of the created index.
Create a new index. Arguments: * `conn` -- The database connection * `collection` -- The collection to operate on * `index-keys` -- Map of index name to index type (1, -1, 2d, 2dsphere, text) Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace * `background?` -- Create index in the background * `bits` -- 2d index location geodata hash precision bits * `collation-options` -- Map of collation options, see [[murmeli.impl.data-interop/make-collation]] * `default-language` -- Text index language * `expire-after-seconds` -- TTL for removing indexed documents * `hidden?` -- Hide index from the query planner * `language-override` -- Name of the field that contains the language string * `max-boundary` -- Upper inclusive boundary for the longitude and latitude values for 2d indexes * `min-boundary` -- Lower inclusive boundary for the longitude and latitude values for 2d indexes * `index-name` -- Name of the index * `partial-filter-expression` -- Filter expression (a map) for including documents in the index * `sparse?` -- Create a sparse index * `sphere-version` -- The 2dsphere index version number * `storage-engine` -- Map of storage engine options * `text-version` -- The text index version number * `unique?` -- Create a unique index * `version` -- The index version number * `weights` -- Map of text index field weights * `wildcard-projection` -- Map of fields to include/exclude in a wildcard index Returns the name of the created index.
(create-object-id)
Returns a new unique org.bson.types.ObjectId
instance.
Returns a new unique `org.bson.types.ObjectId` instance.
(delete-many! conn collection query & {:as options})
Delete document(s) based on the given collection and query.
Returns a map, where
:acknowledged?
-- True if the deletion was acknowledged.:count
-- Number of documents deleted.Delete document(s) based on the given collection and query. Returns a map, where * `:acknowledged?` -- True if the deletion was acknowledged. * `:count` -- Number of documents deleted.
(delete-one! conn collection query & {:as options})
Delete a single document based on the given collection and query.
Returns a map, where
:acknowledged?
-- True if the deletion was acknowledged.:count
-- Number of documents deleted.Delete a single document based on the given collection and query. Returns a map, where * `:acknowledged?` -- True if the deletion was acknowledged. * `:count` -- Number of documents deleted.
(drop-all-indexes! conn collection)
Drop all indexes (except for _id
) in the given collection.
Returns nil
.
Drop all indexes (except for `_id`) in the given collection. Returns `nil`.
(drop-collection! conn collection)
Drop the given collection from the database.
Returns nil
.
Drop the given collection from the database. Returns `nil`.
(drop-db! conn database-name)
Drop the given database.
Does nothing, if the database does not exist.
Returns nil
.
Drop the given database. Does nothing, if the database does not exist. Returns `nil`.
(drop-index! conn collection index-keys)
Drop a specific index (as per the keys) in the given collection.
Returns nil
.
Drop a specific index (as per the keys) in the given collection. Returns `nil`.
(drop-index-by-name! conn collection index-name)
Drop a specific index (as per the name) in the given collection.
Returns nil
.
Drop a specific index (as per the name) in the given collection. Returns `nil`.
(estimated-count-collection conn collection)
Estimate the number of documents in a collection.
Returns the number of documents.
Estimate the number of documents in a collection. Returns the number of documents.
(find-all conn
collection
&
{:keys [allow-qualified? batch-size keywords? limit max-time-ms
projection query sanitize-strings? skip sort]})
Like find-reducible
, but eagerly realizes all matches into a vector.
Like [[find-reducible]], but eagerly realizes all matches into a vector.
(find-by-id conn
collection
id
&
{:keys [allow-qualified? keywords? projection sanitize-strings?]})
Like find-one
, but fetches a single document by id.
Like [[find-one]], but fetches a single document by id.
(find-distinct conn
collection
field
&
{:keys [allow-qualified? batch-size keywords? max-time-ms query
sanitize-strings?]})
Find all distinct value of a field in a collection.
Returns a set containing the distinct values.
Find all distinct value of a field in a collection. Returns a set containing the distinct values.
(find-distinct-reducible conn
collection
field
&
{:keys [allow-qualified? batch-size keywords?
max-time-ms query sanitize-strings?]})
Find all distinct value of a field in a collection.
Returns a reducible (IReduceInit),
which can be reduced (using reduce
, into
, transduce
, run!
..) to execute the query and produce the distinct values.
Find all distinct value of a field in a collection. Returns a reducible ([IReduceInit](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IReduceInit.java)), which can be reduced (using `reduce`, `into`, `transduce`, `run!`..) to execute the query and produce the distinct values.
(find-one conn
collection
&
{:keys [allow-qualified? keywords? projection query sanitize-strings?
throw-on-multiple? warn-on-multiple?]})
Like find-all
, but fetches a single document
By default will warn & throw if the query produces more than one document.
Like [[find-all]], but fetches a single document By default will warn & throw if the query produces more than one document.
(find-one-and-delete! conn
collection
query
&
{:keys [allow-qualified? collation-options comment hint
keywords? max-time-ms projection sanitize-strings?
sort variables]})
Find a document and remove it.
Returns the document, or nil
if none found.
Find a document and remove it. Returns the document, or `nil` if none found.
(find-one-and-replace! conn
collection
query
replacement
&
{:keys [allow-qualified? bypass-validation?
collation-options comment hint keywords?
max-time-ms projection return sanitize-strings?
sort upsert? variables]})
Find a document and replace it.
Returns the document, or nil
if none found. The return
argument controls
whether we return the document before or after the replacement.
Find a document and replace it. Returns the document, or `nil` if none found. The `return` argument controls whether we return the document before or after the replacement.
(find-one-and-update! conn
collection
query
updates
&
{:keys [allow-qualified? array-filters bypass-validation?
collation-options comment hint keywords?
max-time-ms projection return sanitize-strings?
sort upsert? variables]})
Find a document and update it.
Returns the document, or ´nil´ if none found. The return
argument controls
whether we return the document before or after the replacement.
Find a document and update it. Returns the document, or ´nil´ if none found. The `return` argument controls whether we return the document before or after the replacement.
(find-reducible conn
collection
&
{:keys [allow-qualified? batch-size keywords? limit max-time-ms
projection query sanitize-strings? skip sort]})
Query for documents in the given collection.
Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespacebatch-size
-- Fetch documents in N sized batcheskeywords?
-- Decode map keys as keywords instead of stringslimit
-- Limit number of results to returnmax-time-ms
-- Maximum execution time on server in millisecondsprojection
-- Either a sequence of field names or a map of field names to projection typesquery
-- Map describing the query to runskip
-- Skip first N documentssort
-- Map of field name to sort typeReturns a reducible (IReduceInit),
which can be reduced (using reduce
, into
, transduce
, run!
..). to execute the query and produce the matched documents.
Query for documents in the given collection. Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace * `batch-size` -- Fetch documents in N sized batches * `keywords?` -- Decode map keys as keywords instead of strings * `limit` -- Limit number of results to return * `max-time-ms` -- Maximum execution time on server in milliseconds * `projection` -- Either a sequence of field names or a map of field names to projection types * `query` -- Map describing the query to run * `skip` -- Skip first N documents * `sort` -- Map of field name to sort type Returns a reducible ([IReduceInit](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IReduceInit.java)), which can be reduced (using `reduce`, `into`, `transduce`, `run!`..). to execute the query and produce the matched documents.
(id? id)
Returns true if given string represents an object id.
Returns true if given string represents an object id.
(insert-many! conn
collection
docs
&
{:keys [allow-qualified? sanitize-strings?]})
Insert multiple documents into a collection.
If the documents do not contain _id
fields, one will be generated (by default an ObjectId
).
Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespaceReturns a vector containing the _id
s of the inserted documents (String
or ObjectId
) in the corresponding order.
Insert multiple documents into a collection. If the documents do not contain `_id` fields, one will be generated (by default an `ObjectId`). Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace Returns a vector containing the `_id`s of the inserted documents (`String` or `ObjectId`) in the corresponding order.
(insert-one! conn collection doc & {:keys [allow-qualified? sanitize-strings?]})
Insert a single document into a collection
If the document does not contain an _id
field, one will be generated (by default an ObjectId
).
Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespaceReturns the _id
of the inserted document (String
or ObjectId
).
Insert a single document into a collection If the document does not contain an `_id` field, one will be generated (by default an `ObjectId`). Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace Returns the `_id` of the inserted document (`String` or `ObjectId`).
(list-collection-names conn & {:keys [batch-size max-time-ms keywords?]})
Query the collections names in the database.
Options:
batch-size
-- Number of documents per batchmax-time-ms
-- Maximum execution time on server in millisecondskeywords?
-- If true, return collection names as keywordsReturns a set of collection names.
Query the collections names in the database. Options: * `batch-size` -- Number of documents per batch * `max-time-ms` -- Maximum execution time on server in milliseconds * `keywords?` -- If true, return collection names as keywords Returns a set of collection names.
(list-dbs conn)
Query all the databases as documents.
Returns a vector of maps, where each map contains keys like :name
, :sizeOnDisk
, :empty
.
Query all the databases as documents. Returns a vector of maps, where each map contains keys like `:name`, `:sizeOnDisk`, `:empty`.
(list-indexes conn collection & {:keys [batch-size max-time-ms keywords?]})
Query all indexes in the given collection.
Returns a vector of maps, where each map contains keys like :name
, :key
,...
Query all indexes in the given collection. Returns a vector of maps, where each map contains keys like `:name`, `:key`,...
(object-id? id)
Returns true if given object is an org.bson.types.ObjectId
.
Returns true if given object is an `org.bson.types.ObjectId`.
(replace-one! conn
collection
query
changes
&
{:keys [allow-qualified? bypass-validation? collation-options
comment hint keywords? sanitize-strings? upsert?
variables]})
Find document(s) matching query
and replace the first one.
Returns a map, where
:matched
-- Number of documents matched.:modified
-- Number of documents modified.Find document(s) matching `query` and replace the first one. Returns a map, where * `:matched` -- Number of documents matched. * `:modified` -- Number of documents modified.
(update-many! conn
collection
query
changes
&
{:keys [allow-qualified? array-filters bypass-validation?
collation-options comment hint sanitize-strings? upsert?
variables]})
Find document(s) matching query
and apply changes
to them.
Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespacearray-filters
-- List of array filter documentsbypass-validation?
-- If true, bypass document validationcollation-options
-- Map of collation options, see murmeli.impl.data-interop/make-collation
comment
-- Operation comment stringhint
-- Indexing hint documentupsert?
-- If true, insert changes
document if no existing document matches query
variables
-- Top-level variable documentsReturns a map, where
:matched
-- Number of documents matched.:modified
-- Number of documents modified.Find document(s) matching `query` and apply `changes` to them. Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace * `array-filters` -- List of array filter documents * `bypass-validation?` -- If true, bypass document validation * `collation-options` -- Map of collation options, see [[murmeli.impl.data-interop/make-collation]] * `comment` -- Operation comment string * `hint` -- Indexing hint document * `upsert?` -- If true, insert `changes` document if no existing document matches `query` * `variables` -- Top-level variable documents Returns a map, where * `:matched` -- Number of documents matched. * `:modified` -- Number of documents modified.
(update-one! conn
collection
query
changes
&
{:keys [allow-qualified? array-filters bypass-validation?
collation-options comment hint upsert? variables]})
Find document matching query
and apply changes
to it.
Options:
allow-qualified?
-- Accept qualified idents (keywords or symbols), even though we discard the namespacearray-filters
-- List of array filter documentsbypass-validation?
-- If true, bypass document validationcollation-options
-- Map of collation options, see murmeli.impl.data-interop/make-collation
comment
-- Operation comment stringhint
-- Indexing hint documentupsert?
-- If true, insert changes
document if no existing document matches query
variables
-- Top-level variable documentsReturns a map, where
:matched
-- Number of documents matched.:modified
-- Number of documents modified.Find document matching `query` and apply `changes` to it. Options: * `allow-qualified?` -- Accept qualified idents (keywords or symbols), even though we discard the namespace * `array-filters` -- List of array filter documents * `bypass-validation?` -- If true, bypass document validation * `collation-options` -- Map of collation options, see [[murmeli.impl.data-interop/make-collation]] * `comment` -- Operation comment string * `hint` -- Indexing hint document * `upsert?` -- If true, insert `changes` document if no existing document matches `query` * `variables` -- Top-level variable documents Returns a map, where * `:matched` -- Number of documents matched. * `:modified` -- Number of documents modified.
(with-client-session-options conn
&
{:keys [causally-consistent? default-timeout-ms
read-concern read-preference snapshot?
write-concern]})
Store session options into conn
, read by with-session
Store session options into `conn`, read by `with-session`
(with-db conn database-name)
Retrieve a database using the client and store it in the connection.
Retrieve a database using the client and store it in the connection.
(with-session [sym conn :as bindings] & body)
Run body
in a session/transaction.
Gets the session options (as set by with-client-session-options
), starts a session and stores it
in conn
and binds the result to sym
. The session/transaction is either committed or aborted
depending on whether body
throws or not.
Run `body` in a session/transaction. Gets the session options (as set by `with-client-session-options`), starts a session and stores it in `conn` and binds the result to `sym`. The session/transaction is either committed or aborted depending on whether `body` throws or not.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close