Trait musty::MongoModel
source · pub trait MongoModel<I: IdGuard>where
Self: Model<I>,{
const COLLECTION_NAME: &'static str;
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<I, 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<I, 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<'life0, 'async_trait, F, O>(
db: &'life0 Db<Database>,
filter: F,
options: O
) -> Pin<Box<dyn Future<Output = Result<MongoCursor<I, 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,
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>>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_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,
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>>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_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,
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>>where
F: Into<Document> + Send + 'async_trait,
O: Into<Option<FindOneAndDeleteOptions>> + 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,
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>>where
F: Into<Document> + Send + 'async_trait,
O: Into<Option<DeleteOptions>> + 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,
Deletes all documents in the collection that match the given filter