/// Save current object to collection.
/// If collection has a id, existing collection will be updated.
/// If id is `None` then a new id will be created
/// To save the instance update method is called with upsert set to true.
Save current object to collection.
If collection has a id, existing collection will be updated.
If id is `None` then a new id will be created
To save the instance update method is called with upsert set to true.
Save current object to collection . If collection has a id existing collection will be updated . If id is ` None ` then a new id will be created To save the instance update method is called with upsert set to true .
async fn save(&mut self, db: Database) -> Result<()> {
        let collection = Self::collection(db);
        let mut write_concern = Self::write_concern().unwrap_or_default();
        write_concern.journal = Some(true);
        if self.id().is_none() {
            self.set_id(ObjectId::new());
        }
        let doc = self.into_document()?;
        collection
            .update_one(
                doc! { "_id": self.id().unwrap() },
                doc,
                options::UpdateOptions::builder()
                    .upsert(Some(true))
                    .write_concern(write_concern)
                    .build(),
            )
            .await?;
        Ok(())
    }
async fn save ( & mut self , db : Database ) -> Result < ( ) > { let collection = Self :: collection ( db ) ; let mut write_concern = Self :: write_concern ( ) . unwrap_or_default ( ) ; write_concern . journal = Some ( true ) ; if self . id ( ) . is_none ( ) { self . set_id ( ObjectId :: new ( ) ) ; } let doc = self . into_document ( ) ? ; collection . update_one ( doc ! { " " self id ( ) unwrap ( ) } , doc , options :: UpdateOptions :: builder ( ) . upsert ( Some ( true ) ) . write_concern ( write_concern ) . build ( ) , ) . await ? ; Ok ( ( ) ) }
Save current object to collection.
Save current object to collection .
&mut self
db
Database