-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
Currently, if a user wishes to insert an instance of their struct, they must first convert it to bson and then either use as_document + clone, unwrap it manually via a match statement, or use both to_bson and from_bson. These are all quite verbose and could be shortened if it were possible to serialize something directly to Document.
coll.insert_one(bson::to_document(post)?, None).await?
// vs
coll.insert_one(bson::from_bson(bson::to_bson(post)?)?, None).await?
See discussion on GitHub: https://github.com/mongodb/bson-rust/issues/128