MongoModel

Trait MongoModel 

Source
pub trait MongoModel
where 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 { ... } }
Available on crate feature mongodb only.
Expand description

Exposes MongoDB operations for a model.

Required Associated Constants§

Source

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§

Source

fn read_concern() -> Option<ReadConcern>

The read concern for MongoDB for this collection

Source

fn write_concern() -> Option<WriteConcern>

The write concern for MongoDB for this collection

Source

fn selection_criteria() -> Option<SelectionCriteria>

The selection criteria for MongoDB for this collection

Source

fn collection(db: &Db<Database>) -> Collection<Self>

The collection for this model

Source

fn document_from_model(&self) -> Result<Document>

Converts the model to a BSON document

Source

fn model_from_document(document: Document) -> Result<Self>

Converts a BSON document to this model type

Source

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,

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

Source

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

Source

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

Source

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

Source

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

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.

Implementors§