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

mongo-rust-driver - PR #1108: Macro for field projection proposal

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      yourlogarithm has created PR #1108: Macro for field projection proposal in mongo-rust-driver

      Issue Text:
      Usage example

      ```bash
      cargo add mongodb -F projection_macro
      ```

      ```rust
      use mongodb::options::

      {FindOptions, Project}

      ;
      use serde::Deserialize;

      #[derive(Project, Deserialize)]
      struct Person

      { #[serde(rename = "n")] name: String, age: u8, male: bool, #[serde(rename = "h.a")] address: String, }

      #[tokio::main]
      async fn main() {
      let client = mongodb::Client::with_uri_str("mongodb://localhost:27017").await.unwrap();
      let projection = Person::project().name().age().address().build();
      println!("{:?}", projection); // mongodb::bson::Document(

      {"n": Int32(1), "age": Int32(1), "h.a": Int32(1)}

      )
      let options = FindOptions::builder().projection(projection).build();
      let document = client.database("test").collection("people").find_one(None, options).unwrap().unwrap();
      }
      ```

            Assignee:
            abraham.egnor@mongodb.com Abraham Egnor
            Reporter:
            jira.automation JIRA Automation
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: