-
Couldn't load subscription status.
- Fork 190
Closed
Description
I just had a lot of trouble finding how to update a document in my collection, which has a value that isn't primitive (a structure here in my example).
I was trying to set the "oders" fields.
And I had to look for some time to find that you can use bson::to_bson to Sereliaze the structure.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Turtle {
name: String,
pub orders: Vec<Command>,
pub infos: HashMap<String, String>,
pos: Position,
facing: Facing,
}
let result = turtles
.update_one(
doc! { "name": &name },
doc! { "$set": { "orders": bson::to_bson(&orders).expect("Unable to convert orders to bson") } },
None,
)
.await
.expect("Unable to update orders of the turtle");Could we add an example about bson::to_bson and perhaps also about updating in the README.md usage section ?
I can do it and open a Pull requests if it helps 👍
Metadata
Metadata
Assignees
Labels
No labels