pub struct Model<'a, M>where
M: Boot,{ /* private fields */ }Implementations§
Source§impl<'a, M> Model<'a, M>
impl<'a, M> Model<'a, M>
pub fn new( db: &Database, collection_name: &'a str, columns: &'a str, add_times: bool, ) -> Model<'a, M>
Sourcepub fn set_request(self, req: M::Req) -> Model<'a, M>
pub fn set_request(self, req: M::Req) -> Model<'a, M>
Set Request to model
Sourcepub fn add_columns(&mut self, names: Vec<&'a str>)
pub fn add_columns(&mut self, names: Vec<&'a str>)
add lazy column to model
Sourcepub fn collection_name(&self) -> &'a str
pub fn collection_name(&self) -> &'a str
Gets the collection name
Sourcepub fn collection(&self) -> Collection<M>
pub fn collection(&self) -> Collection<M>
Gets a handle to the MongoDB collection
Sourcepub fn set_collection(self, name: &'a str) -> Model<'a, M>
pub fn set_collection(self, name: &'a str) -> Model<'a, M>
Changes the collection name for this model
Sourcepub async fn register_indexes(&self)
pub async fn register_indexes(&self)
Registers indexes based on column attributes
This will:
- Check existing indexes
- Remove indexes for fields that no longer exist in the model
- Create new indexes for fields marked as indexes in column attributes
Sourcepub fn batch_size(self, value: u32) -> Model<'a, M>
pub fn batch_size(self, value: u32) -> Model<'a, M>
The number of documents the server should return per cursor batch.
Sourcepub fn all(self) -> Model<'a, M>
pub fn all(self) -> Model<'a, M>
Sets whether to affect all matching documents (for update/delete)
Source§impl<'a, M> Model<'a, M>
impl<'a, M> Model<'a, M>
Sourcepub fn take_inner(&mut self) -> M
pub fn take_inner(&mut self) -> M
this method takes the inner and gives you ownership of inner then replace it with default value
pub fn inner_ref(&self) -> &M
pub fn inner_mut(&mut self) -> &mut M
pub fn inner_to_doc(&self) -> MongodbResult<Document>
pub fn fill(self, inner: M) -> Model<'a, M>
Source§impl<'a, M> Model<'a, M>
impl<'a, M> Model<'a, M>
Sourcepub async fn count_documents(self) -> Result<u64>
pub async fn count_documents(self) -> Result<u64>
Get Documents count with filters
Sourcepub async fn count_documents_with_session(
self,
session: &mut ClientSession,
) -> Result<u64>
pub async fn count_documents_with_session( self, session: &mut ClientSession, ) -> Result<u64>
Get Documents count with filters and session
Sourcepub async fn create(&self) -> Result<InsertOneResult>
pub async fn create(&self) -> Result<InsertOneResult>
Sourcepub async fn create_with_session(
&self,
session: &mut ClientSession,
) -> Result<InsertOneResult>
pub async fn create_with_session( &self, session: &mut ClientSession, ) -> Result<InsertOneResult>
Sourcepub async fn create_doc(&self, data: Document) -> Result<InsertOneResult>
pub async fn create_doc(&self, data: Document) -> Result<InsertOneResult>
Creates a new document from raw BSON
Sourcepub async fn create_doc_with_session(
&self,
data: Document,
session: &mut ClientSession,
) -> Result<InsertOneResult>
pub async fn create_doc_with_session( &self, data: Document, session: &mut ClientSession, ) -> Result<InsertOneResult>
Creates a new document from raw BSON with session
Sourcepub async fn create_many_doc(
&self,
data: Vec<Document>,
) -> Result<InsertManyResult>
pub async fn create_many_doc( &self, data: Vec<Document>, ) -> Result<InsertManyResult>
Creates many document from raw BSON
Sourcepub async fn create_many_doc_with_session(
&self,
data: Vec<Document>,
session: &mut ClientSession,
) -> Result<InsertManyResult>
pub async fn create_many_doc_with_session( &self, data: Vec<Document>, session: &mut ClientSession, ) -> Result<InsertManyResult>
Creates many document from raw BSON with session
Sourcepub async fn update_with_session(
&self,
data: Document,
session: &mut ClientSession,
) -> Result<Document>
pub async fn update_with_session( &self, data: Document, session: &mut ClientSession, ) -> Result<Document>
Sourcepub async fn delete(&self) -> Result<Document>
pub async fn delete(&self) -> Result<Document>
Deletes documents from the collection
§Notes
- Handles both single and multi-document deletes based on
all()setting
Sourcepub async fn delete_with_session(
&self,
session: &mut ClientSession,
) -> Result<Document>
pub async fn delete_with_session( &self, session: &mut ClientSession, ) -> Result<Document>
Sourcepub async fn get(&self) -> Result<Vec<M>>
pub async fn get(&self) -> Result<Vec<M>>
Queries documents from the collection
§Notes
- Respects skip/limit/sort/select settings
- Filters out hidden fields unless explicitly made visible
Sourcepub async fn get_with_session(
&self,
session: &mut ClientSession,
) -> Result<Vec<M>>
pub async fn get_with_session( &self, session: &mut ClientSession, ) -> Result<Vec<M>>
Sourcepub async fn first_with_session(
&mut self,
session: &mut ClientSession,
) -> Result<Option<M>>
pub async fn first_with_session( &mut self, session: &mut ClientSession, ) -> Result<Option<M>>
Gets the first matching document with session
Sourcepub async fn aggregate(
&mut self,
pipeline: impl IntoIterator<Item = Document>,
) -> Result<Vec<M>>
pub async fn aggregate( &mut self, pipeline: impl IntoIterator<Item = Document>, ) -> Result<Vec<M>>
Runs an aggregation pipeline
Sourcepub async fn aggregate_with_session(
&mut self,
pipeline: impl IntoIterator<Item = Document>,
session: &mut ClientSession,
) -> Result<Vec<M>>
pub async fn aggregate_with_session( &mut self, pipeline: impl IntoIterator<Item = Document>, session: &mut ClientSession, ) -> Result<Vec<M>>
Runs an aggregation pipeline with session
Sourcepub async fn get_doc(&self) -> Result<Vec<Document>>
pub async fn get_doc(&self) -> Result<Vec<Document>>
Queries documents from the collection
§Notes
- Respects skip/limit/sort/select settings
- Filters out hidden fields unless explicitly made visible
Sourcepub async fn get_doc_with_session(
&self,
session: &mut ClientSession,
) -> Result<Vec<Document>>
pub async fn get_doc_with_session( &self, session: &mut ClientSession, ) -> Result<Vec<Document>>
Sourcepub async fn first_doc_with_session(
&mut self,
session: &mut ClientSession,
) -> Result<Option<Document>>
pub async fn first_doc_with_session( &mut self, session: &mut ClientSession, ) -> Result<Option<Document>>
Gets the first matching document with session
Sourcepub async fn aggregate_doc(
&mut self,
pipeline: impl IntoIterator<Item = Document>,
) -> Result<Vec<Document>>
pub async fn aggregate_doc( &mut self, pipeline: impl IntoIterator<Item = Document>, ) -> Result<Vec<Document>>
Runs an aggregation pipeline
Sourcepub async fn aggregate_doc_with_session(
&mut self,
pipeline: impl IntoIterator<Item = Document>,
session: &mut ClientSession,
) -> Result<Vec<Document>>
pub async fn aggregate_doc_with_session( &mut self, pipeline: impl IntoIterator<Item = Document>, session: &mut ClientSession, ) -> Result<Vec<Document>>
Runs an aggregation pipeline with session
Sourcepub async fn cursor(&self) -> Result<Cursor<Document>>
pub async fn cursor(&self) -> Result<Cursor<Document>>
Creates a cursor for iterating over documents in the collection.
§Returns
Result<Cursor<Document>>: A MongoDB cursor that can be used to iterate over documents- Returns an error if the query execution fails
§Example
let cursor = User::new_model(db).cursor().await?;
while let Some(doc) = cursor.next().await {
// process document
}pub async fn cursor_with_session( &self, session: &mut ClientSession, ) -> Result<SessionCursor<Document>>
Trait Implementations§
Auto Trait Implementations§
impl<'a, M> Freeze for Model<'a, M>
impl<'a, M> !RefUnwindSafe for Model<'a, M>
impl<'a, M> Send for Model<'a, M>
impl<'a, M> Sync for Model<'a, M>
impl<'a, M> Unpin for Model<'a, M>
impl<'a, M> !UnwindSafe for Model<'a, M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random to avoid conflict with the new gen keyword in Rust 2024.Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_rangeRng::random_range.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore to a RngReadAdapter.