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

impl Client[src]

pub async fn with_uri_str(uri: impl AsRef<str>) -> Result<Self>[src]

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.

pub fn with_options(options: ClientOptions) -> Result<Self>[src]

Creates a new Client connected to the cluster specified by options.

pub fn selection_criteria(&self) -> Option<&SelectionCriteria>[src]

Gets the default selection criteria the Client uses for operations..

pub fn read_concern(&self) -> Option<&ReadConcern>[src]

Gets the default read concern the Client uses for operations.

pub fn write_concern(&self) -> Option<&WriteConcern>[src]

Gets the default write concern the Client uses for operations.

pub fn database(&self, name: &str) -> Database[src]

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.

pub fn database_with_options(
    &self,
    name: &str,
    options: DatabaseOptions
) -> Database
[src]

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>>
[src]

Gets information about each database present in the cluster the Client is connected to.

pub async fn list_database_names(
    &self,
    filter: impl Into<Option<Document>>,
    options: impl Into<Option<ListDatabasesOptions>>
) -> Result<Vec<String>>
[src]

Gets the names of the databases present in the cluster the Client is connected to.

pub async fn start_session(
    &self,
    options: Option<SessionOptions>
) -> Result<ClientSession>
[src]

Starts a new ClientSession.

Trait Implementations

impl Clone for Client[src]

fn clone(&self) -> Client[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Client[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl From<Client> for Client[src]

This is supported on crate feature sync only.

fn from(async_client: AsyncClient) -> Self[src]

Performs the conversion.

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V