Struct mongod::query::Update[][src]

pub struct Update<C: Collection> { /* fields omitted */ }

A querier to update documents in a MongoDB collection.

Examples

Updates some documents in a collection.

#[derive(Bson, Mongo)]
#[mongo(collection="users", field, filter, update)]
pub struct User {
    name: String,
    age: Option<u32>,
    email: Option<String>,
}
use mongod::{AsFilter, Comparator, AsUpdate};

let client = mongod::Client::new();

let mut filter = User::filter();
filter.name = Some(Comparator::Eq("foo".to_owned()));

let mut update = User::update();
update.name = Some("bar".to_owned());

let updates = mongod::Updates {
    set: Some(update),
    ..Default::default()
};

let updated = mongod::query::Update::<User>::new()
    .filter(filter)
    .unwrap()
    .query(&client, updates)
    .await
    .unwrap();

println!("updated {} documents", updated);

Implementations

impl<C: Collection> Update<C>[src]

pub fn new() -> Self[src]

Constructs an Update querier.

pub fn array_filters(self, filters: Vec<Document>) -> Self[src]

An array of filters specifying to which array elements an update should apply.

pub fn bypass_document_validation(self, enable: bool) -> Self[src]

Opt out of document-level validation.

pub fn collation(self, collation: Collation) -> Self[src]

The collation to use for the operation.

Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks.

pub fn filter<F>(self, filter: F) -> Result<Self, Error> where
    C: AsFilter<F>,
    F: Filter
[src]

The filter to use for the operation.

Errors

This method errors if the filter could not be converted into a BSON Document.

pub fn hint(self, value: Hint) -> Self[src]

A document or string that specifies the index to use to support the query predicate.

pub fn many(self, enable: bool) -> Self[src]

Enable update many for this operation.

Removes all documents that match the filter from a collection.

pub fn upsert(self, enable: bool) -> Self[src]

Insert a document if no matching document is found.

pub fn write_concern(self, concern: WriteConcern) -> Self[src]

The write concern for the operation.

pub async fn query<U>(
    self,
    client: &Client,
    updates: Updates<U>
) -> Result<i64, Error> where
    C: AsUpdate<U>,
    U: Update
[src]

Query the database with this querier.

Errors

This method fails if:

  • the updates could not be converted into a BSON Document.
  • the mongodb encountered an error.

pub fn blocking<U>(
    self,
    client: &Client,
    updates: Updates<U>
) -> Result<i64, Error> where
    C: AsUpdate<U>,
    U: Update
[src]

Query the database with this querier in a blocking context.

Optional

This requires the optional blocking feature to be enabled.

Errors

This method fails if:

  • the updates could not be converted into a BSON Document.
  • the mongodb encountered an error.

Trait Implementations

impl<C: Clone + Collection> Clone for Update<C>[src]

impl<C: Collection> Default for Update<C>[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for Update<C> where
    C: RefUnwindSafe
[src]

impl<C> Send for Update<C> where
    C: Send
[src]

impl<C> Sync for Update<C> where
    C: Sync
[src]

impl<C> Unpin for Update<C> where
    C: Unpin
[src]

impl<C> UnwindSafe for Update<C> where
    C: UnwindSafe
[src]

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> 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>,