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
| Name | Description |
|---|---|
| $inc | Increments the value of the field by the specified amount. |
| $min | Only updates the field if the specified value is less than the existing field value. |
| $max | Only updates the field if the specified value is greater than the existing field value. |
| $mul | Multiplies the value of the field by the specified amount. |
| $rename | Renames a field. |
| $set | Sets the value of a field in a document. |
| $unset | Removes the specified field from a document. |