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
sourceimpl<C: Collection> Update<C>
impl<C: Collection> Update<C>
sourcepub fn array_filters(self, filters: Vec<Document>) -> Self
pub fn array_filters(self, filters: Vec<Document>) -> Self
An array of filters specifying to which array elements an update should apply.
sourcepub fn bypass_document_validation(self, enable: bool) -> Self
pub fn bypass_document_validation(self, enable: bool) -> Self
Opt out of document-level validation.
sourcepub fn collation(self, collation: Collation) -> Self
pub fn collation(self, collation: Collation) -> Self
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.
sourcepub fn filter<F>(self, filter: F) -> Result<Self, Error> where
C: AsFilter<F>,
F: Filter,
pub fn filter<F>(self, filter: F) -> Result<Self, Error> where
C: AsFilter<F>,
F: Filter,
The filter to use for the operation.
Errors
This method errors if the filter could not be converted into a BSON Document
.
sourcepub fn hint(self, value: Hint) -> Self
pub fn hint(self, value: Hint) -> Self
A document or string that specifies the index to use to support the query predicate.
sourcepub fn many(self, enable: bool) -> Self
pub fn many(self, enable: bool) -> Self
Enable update many for this operation.
Removes all documents that match the filter from a collection.
sourcepub fn write_concern(self, concern: WriteConcern) -> Self
pub fn write_concern(self, concern: WriteConcern) -> Self
The write concern for the operation.
sourcepub async fn query<U>(
self,
client: &Client,
updates: Updates<U>
) -> Result<i64, Error> where
C: AsUpdate<U>,
U: Update,
pub async fn query<U>(
self,
client: &Client,
updates: Updates<U>
) -> Result<i64, Error> where
C: AsUpdate<U>,
U: Update,
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.
Trait Implementations
sourceimpl<C: Clone + Collection> Clone for Update<C>
impl<C: Clone + Collection> Clone for Update<C>
Auto Trait Implementations
impl<C> RefUnwindSafe for Update<C> where
C: RefUnwindSafe,
impl<C> Send for Update<C> where
C: Send,
impl<C> Sync for Update<C> where
C: Sync,
impl<C> Unpin for Update<C> where
C: Unpin,
impl<C> UnwindSafe for Update<C> where
C: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more