pub trait MongoModelwhere
Self: Model,{
const COLLECTION_NAME: &'static str;
// Provided methods
fn read_concern() -> Option<ReadConcern> { ... }
fn write_concern() -> Option<WriteConcern> { ... }
fn selection_criteria() -> Option<SelectionCriteria> { ... }
fn collection(db: &Db<Database>) -> Collection<Self> { ... }
fn document_from_model(&self) -> Result<Document> { ... }
fn model_from_document(document: Document) -> Result<Self> { ... }
fn find<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O,
) -> Pin<Box<dyn Future<Output = Result<MongoCursor<Self>>> + Send + 'async_trait>>
where F: Into<Option<Document>> + Send + 'async_trait,
O: Into<Option<FindOptions>> + Send + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn find_one_and_replace<'life0, 'life1, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
replacement: &'life1 Self,
options: O,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
where F: Into<Document> + Send + 'async_trait,
O: Into<Option<FindOneAndReplaceOptions>> + Send + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn find_one_and_update<'life0, 'async_trait, F, U, O>(
db: &'life0 Db<Database>,
filter: F,
update: U,
options: O,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
where F: Into<Document> + Send + 'async_trait,
U: Into<UpdateModifications> + Send + 'async_trait,
O: Into<Option<FindOneAndUpdateOptions>> + Send + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn find_one_and_delete<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
where F: Into<Document> + Send + 'async_trait,
O: Into<Option<FindOneAndDeleteOptions>> + Send + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn delete_many<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>>
where F: Into<Document> + Send + 'async_trait,
O: Into<Option<DeleteOptions>> + Send + 'async_trait,
Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}mongodb only.Expand description
Exposes MongoDB operations for a model.
Required Associated Constants§
Sourceconst COLLECTION_NAME: &'static str
const COLLECTION_NAME: &'static str
The collection name for this model
Automatically implemented
Can be set using #[model(collection_name = "name")] on the model struct
Provided Methods§
Sourcefn read_concern() -> Option<ReadConcern>
fn read_concern() -> Option<ReadConcern>
The read concern for MongoDB for this collection
Sourcefn write_concern() -> Option<WriteConcern>
fn write_concern() -> Option<WriteConcern>
The write concern for MongoDB for this collection
Sourcefn selection_criteria() -> Option<SelectionCriteria>
fn selection_criteria() -> Option<SelectionCriteria>
The selection criteria for MongoDB for this collection
Sourcefn collection(db: &Db<Database>) -> Collection<Self>
fn collection(db: &Db<Database>) -> Collection<Self>
The collection for this model
Sourcefn document_from_model(&self) -> Result<Document>
fn document_from_model(&self) -> Result<Document>
Converts the model to a BSON document
Sourcefn model_from_document(document: Document) -> Result<Self>
fn model_from_document(document: Document) -> Result<Self>
Converts a BSON document to this model type
Sourcefn find<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O,
) -> Pin<Box<dyn Future<Output = Result<MongoCursor<Self>>> + Send + 'async_trait>>
fn find<'life0, 'async_trait, F, O>( db: &'life0 Db<Database>, filter: F, options: O, ) -> Pin<Box<dyn Future<Output = Result<MongoCursor<Self>>> + Send + 'async_trait>>
Find instances of this model type that match the given filter (ex bson::doc! { "name": "John" })
Returns a MongoCursor which can be used to iterate over the results
Use futures::StreamExt to iterate over the results using
while let Some(result) = cursor.next().await {}
Sourcefn find_one_and_replace<'life0, 'life1, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
replacement: &'life1 Self,
options: O,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
fn find_one_and_replace<'life0, 'life1, 'async_trait, F, O>( db: &'life0 Db<Database>, filter: F, replacement: &'life1 Self, options: O, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
Find a single document and replace it
Sourcefn find_one_and_update<'life0, 'async_trait, F, U, O>(
db: &'life0 Db<Database>,
filter: F,
update: U,
options: O,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
fn find_one_and_update<'life0, 'async_trait, F, U, O>( db: &'life0 Db<Database>, filter: F, update: U, options: O, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
Find a single document and update it
Sourcefn find_one_and_delete<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
fn find_one_and_delete<'life0, 'async_trait, F, O>( db: &'life0 Db<Database>, filter: F, options: O, ) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
Find a single document and delete it
Sourcefn delete_many<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>>
fn delete_many<'life0, 'async_trait, F, O>( db: &'life0 Db<Database>, filter: F, options: O, ) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>>
Deletes all documents in the collection that match the given filter
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.