Struct mongodb::Client [−][src]
pub struct Client { /* fields omitted */ }
Expand description
This is the main entry point for the API. A Client
is used to connect to a MongoDB cluster.
By default, it will monitor the topology of the cluster, keeping track of any changes, such
as servers being added or removed.
Client
uses std::sync::Arc
internally,
so it can safely be shared across threads or async tasks. For example:
let client = Client::with_uri_str("mongodb://example.com").await?;
for i in 0..5 {
let client_ref = client.clone();
task::spawn(async move {
let collection = client_ref.database("items").collection::<Document>(&format!("coll{}", i));
// Do something with the collection
});
}
TCP Keepalive
TCP keepalive is enabled by default with tcp_keepalive_time
set to 120 seconds. The
driver does not set tcp_keepalive_intvl
. See the
MongoDB Diagnostics FAQ keepalive section
for instructions on setting these values at the system level.
Implementations
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Creates a new Client
connected to the cluster specified by uri
. uri
must be a valid
MongoDB connection string.
See the documentation on
ClientOptions::parse
for more details.
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Creates a new Client
connected to the cluster specified by options
.
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets the default selection criteria the Client
uses for operations..
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets the default read concern the Client
uses for operations.
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets the default write concern the Client
uses for operations.
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets a handle to a database specified by name
in the cluster the Client
is connected to.
The Database
options (e.g. read preference and write concern) will default to those of the
Client
.
This method does not send or receive anything across the wire to the database, so it can be used repeatedly without incurring any costs from I/O.
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets a handle to a database specified by name
in the cluster the Client
is connected to.
Operations done with this Database
will use the options specified by options
by default
and will otherwise default to those of the Client
.
This method does not send or receive anything across the wire to the database, so it can be used repeatedly without incurring any costs from I/O.
pub async fn list_databases(
&self,
filter: impl Into<Option<Document>>,
options: impl Into<Option<ListDatabasesOptions>>
) -> Result<Vec<DatabaseSpecification>>
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
pub async fn list_databases(
&self,
filter: impl Into<Option<Document>>,
options: impl Into<Option<ListDatabasesOptions>>
) -> Result<Vec<DatabaseSpecification>>
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets information about each database present in the cluster the Client is connected to.
pub async fn list_databases_with_session(
&self,
filter: impl Into<Option<Document>>,
options: impl Into<Option<ListDatabasesOptions>>,
session: &mut ClientSession
) -> Result<Vec<DatabaseSpecification>>
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
pub async fn list_databases_with_session(
&self,
filter: impl Into<Option<Document>>,
options: impl Into<Option<ListDatabasesOptions>>,
session: &mut ClientSession
) -> Result<Vec<DatabaseSpecification>>
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets information about each database present in the cluster the Client is connected to
using the provided ClientSession
.
pub async fn list_database_names(
&self,
filter: impl Into<Option<Document>>,
options: impl Into<Option<ListDatabasesOptions>>
) -> Result<Vec<String>>
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
pub async fn list_database_names(
&self,
filter: impl Into<Option<Document>>,
options: impl Into<Option<ListDatabasesOptions>>
) -> Result<Vec<String>>
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Gets the names of the databases present in the cluster the Client is connected to.
This is supported on crate feature tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.
tokio-runtime
and non-crate feature async-std-runtime
, or non-crate feature tokio-runtime
and crate feature async-std-runtime
only.Starts a new ClientSession
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
Blanket Implementations
Mutably borrows from an owned value. Read more