Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-503

Support serializing directly to Document

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-1.1.0
    • 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

            Assignee:
            isabel.atkinson@mongodb.com Isabel Atkinson
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: