pub struct Update<C: Collection> { /* private fields */ }
Expand description

A querier to update documents in a MongoDB collection.

Examples

Updates some documents in a collection.

use serde::{Deserialize, Serialize};

#[derive(Bson, Mongo, Deserialize, Serialize)]
#[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

Constructs an Update querier.

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

Opt out of document-level validation.

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.

The filter to use for the operation.

Errors

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

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

Enable update many for this operation.

Removes all documents that match the filter from a collection.

Insert a document if no matching document is found.

The write concern for the operation.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

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

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more