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
, { ... } }
Available on crate feature mongodb only.
Expand description

Exposes MongoDB operations for a model.

Required Associated Constants§

The collection name for this model Automatically implemented Can be set using #[model(collection_name = "name")] on the model struct

Provided Methods§

The read concern for MongoDB for this collection

The write concern for MongoDB for this collection

The selection criteria for MongoDB for this collection

The collection for this model

Converts the model to a BSON document

Converts a BSON document to this model type

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 {}

Find a single document and replace it

Find a single document and update it

Find a single document and delete it

Deletes all documents in the collection that match the given filter

Implementors§