Struct mongod::Client[][src]

pub struct Client { /* fields omitted */ }

An asynchronous Client to query mongo with.

The client uses sane defaults but these can be tweaked using the builder. To configure a Client, use Client::builder.

The Client holds a connection pool internally, so it is advised that you create once, and reuse it.

Implementations

impl Client[src]

pub fn new() -> Self[src]

Constructs a new Client.

Panics

This method panics if the mongodb::Client fails to initialise.

Use Client::builder() if you wish to handle this failure as an Error instead of panicking.

pub fn builder() -> ClientBuilder[src]

Creates a ClientInner to configure a Client.

This is the same as ClientBuilder::new().

pub fn from_client<I: Into<String>>(client: Client, database: I) -> Self[src]

Constructs a new Client using a mongodb::Client.

pub fn client(&self) -> Client[src]

Returns the mongodb::Client

pub fn collection<C>(&self) -> Collection where
    C: Collection
[src]

Returns the mongodb::Document from the mongodb.

pub fn database(&self) -> Database[src]

Returns the mongodb::Database from the mongodb.

pub async fn delete<C, F>(&self, filter: Option<F>) -> Result<i64, Error> where
    C: AsFilter<F> + Collection,
    F: Filter
[src]

Convenience method to delete documents from a collection using a given filter.

Errors

This method fails if the mongodb encountered an error.

pub async fn delete_one<C, F>(&self, filter: F) -> Result<bool, Error> where
    C: AsFilter<F> + Collection,
    F: Filter
[src]

Convenience method to delete one document from a collection using a given filter.

Errors

This method fails if the mongodb encountered an error.

pub async fn find<C, F>(&self, filter: Option<F>) -> Result<Cursor, Error> where
    C: AsFilter<F> + Collection,
    F: Filter
[src]

Convenience method to find documents in a collection.

This function is mainly intended for use cases where the filter is known to return unique hits. If you need something more complicated use find or the FindBuilder.

Errors

This method fails if the mongodb encountered an error.

pub async fn find_one<C, F>(&self, filter: F) -> Result<Option<C>, Error> where
    C: AsFilter<F> + Collection,
    F: Filter
[src]

Convenience method to find a document in a collection using a given filter.

This function is mainly intended for use cases where the filter is known to return unique hits. If you need something more complicated use find or the FindBuilder.

Errors

This method fails if the mongodb encountered an error, or if the found document is invalid.

pub async fn insert<C>(
    &self,
    documents: Vec<C>
) -> Result<HashMap<usize, ObjectId>, Error> where
    C: Collection
[src]

Convenience method to insert documents in a collection.

Errors

This method fails if the mongodb encountered an error, or if the found document is invalid.

pub async fn insert_one<C>(&self, document: C) -> Result<ObjectId, Error> where
    C: Collection
[src]

Convenience method to insert a document in a collection.

Errors

This method fails if the mongodb encountered an error, or if the found document is invalid.

pub async fn replace_one<C, F>(
    &self,
    filter: F,
    document: C
) -> Result<bool, Error> where
    C: AsFilter<F> + Collection,
    F: Filter
[src]

Convenience method to replace a document in a collection.

Errors

This method fails if the mongodb encountered an error.

pub async fn update<C, F, U>(
    &self,
    filter: F,
    updates: Updates<U>
) -> Result<i64, Error> where
    C: AsFilter<F> + AsUpdate<U> + Collection,
    F: Filter,
    U: Update
[src]

Convenience method to update documents in a collection.

Errors

This method fails if the mongodb encountered an error.

pub async fn update_one<C, F, U>(
    &self,
    filter: F,
    updates: Updates<U>
) -> Result<bool, Error> where
    C: AsFilter<F> + AsUpdate<U> + Collection,
    F: Filter,
    U: Update
[src]

Convenience method to update one document from a collection.

Errors

This method fails if the mongodb encountered an error.

pub async fn upsert<C, F, U>(
    &self,
    filter: F,
    updates: Updates<U>
) -> Result<i64, Error> where
    C: AsFilter<F> + AsUpdate<U> + Collection,
    F: Filter,
    U: Update
[src]

Convenience method to upsert documents from a collection.

Errors

This method fails if the mongodb encountered an error.

pub async fn upsert_one<C, F, U>(
    &self,
    filter: F,
    updates: Updates<U>
) -> Result<bool, Error> where
    C: AsFilter<F> + AsUpdate<U> + Collection,
    F: Filter,
    U: Update
[src]

Convenience method to upsert one document from a collection.

Errors

This method fails if the mongodb encountered an error.

Trait Implementations

impl Clone for Client[src]

impl Default for Client[src]

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]

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

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

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

impl<T> Instrument for T[src]

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

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.

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.

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.

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