Trait wither::model::Model [] [src]

pub trait Model<'a> where
    Self: Serialize + Deserialize<'a>, 
{ const COLLECTION_NAME: &'static str; fn id(&self) -> Option<ObjectId>;
fn set_id(&mut self, _: ObjectId); fn model_write_concern() -> WriteConcern { ... }
fn write_concern_w() -> i32 { ... }
fn write_concern_w_timeout() -> i32 { ... }
fn write_concern_j() -> bool { ... }
fn write_concern_fsync() -> bool { ... }
fn find(
        db: Database,
        filter: Option<Document>,
        options: Option<FindOptions>
    ) -> Result<Vec<Self>> { ... }
fn find_one(
        db: Database,
        filter: Option<Document>,
        options: Option<FindOptions>
    ) -> Result<Option<Self>> { ... }
fn save(&mut self, db: Database, filter: Option<Document>) -> Result<()> { ... }
fn instance_from_document(document: Document) -> Result<Self> { ... }
fn indexes() -> Vec<IndexModel> { ... }
fn sync(db: Database) { ... } }

Model provides data modeling behaviors for interacting with MongoDB database collections.

This allows you to define a data model using a normal struct, and then interact with your MongoDB database collections using that struct.

Associated Constants

The name of the collection where this model's data is stored.

Required Methods

Get the ID for this model instance.

Set the ID for this model.

Provided Methods

The model's write concern for database writes.

The default implementation ensures that all writes block until they are journaled, which ensures that an ObjectId will be returned for the inserted document. For most cases, overriding this implementation should be unnecessary.

The write replication settings for this model. Defaults to 1.

The write concern timeout settings for this model. Defaults to 0.

The write concern journal settings for this model. Defaults to true.

The write concern fsync settings for this model. Defaults to false.

Find all instances of this model matching the given query.

Find the one model record matching your query, returning a model instance.

Save the current model instance.

In order to make this method as flexible as possible, its behavior varies a little based on the input and the state of the instance.

When the instance already has an ID, this method will operate purely based on the instance ID. If no ID is present, and no filter has been specified, then an ID will be generated.

If a filter is specified, and no ID exists for the instance, then the filter will be used and the first document matching the filter will be replaced by this instance. This is useful when the model has unique indexes on fields which need to be the target of the save operation.

Attempt to serialize the given bson document into an instance of this model.

Get the vector of index models for this model.

Synchronize this model with the backend.

This routine will destroy any indexes found on this model's collection which are not defined in the response from Self.indexes().

This routine should be called once per model, early on at boot time.

TODO: - build up a safe sync execution standpoint. - return before doing anything if index sync can not be executed safely.

Implementors