docs
CURD
Update

Update

Use update_one to update at most one matching document, or update_many to update every matching document. Both methods return an UpdateResult with matched_count and modified_count fields.

use polodb_core::bson::{doc, Document};
use polodb_core::{CollectionT, Database};
 
fn main() -> polodb_core::Result<()> {
    let db = Database::open_path("./polodb-data")?;
    let collection = db.collection::<Document>("config");
 
    let result = collection.update_one(
        doc! { "_id": "c2" },
        doc! { "$set": { "value": "c33" } },
    )?;
 
    println!(
        "matched: {}, modified: {}",
        result.matched_count,
        result.modified_count,
    );
    Ok(())
}

To apply the same update to every matching document, use update_many with the same filter and update document.

Operations

NameDescription
$incIncrements the value of the field by the specified amount.
$minOnly updates the field if the specified value is less than the existing field value.
$maxOnly updates the field if the specified value is greater than the existing field value.
$mulMultiplies the value of the field by the specified amount.
$renameRenames a field.
$setSets the value of a field in a document.
$unsetRemoves the specified field from a document.