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

All records receive the same ObjectId

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      Each time a new record is inserted the object receives the same ObjectId.

      Sample Code:

      Unable to find source-code formatter for language: rust. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      use std::error::Error;
      use serde::{Deserialize, Serialize};
      use mongodb::{Client, bson::oid::ObjectId};
      
      #[derive(Debug, Deserialize, Serialize)]
      struct Project {
          key: String,
      }
      
      
      #[tokio::main(flavor = "multi_thread", worker_threads = 5)]
      async fn main() -> Result<(), Box<dyn Error>> {
          let client = Client::with_uri_str("mongodb://root:root@localhost:27017").await?;
          let db = client.database("playground");
          let coll = db.collection::<Project>("projects");
          let res = coll.insert_one(Project { key: "test".to_string() }, None).await?;
          println!("{:?}", res);
      
          Ok(())
      }
      

      Every time I run the code above it prints {{InsertOneResult { inserted_id: ObjectId("60fd320b00a3d58a0077e8cb") }}}

       

      Adding an _id: ObjectId field to the struct and then constructing the object as follows  {{Project { _id: ObjectId::new(), key: "test2".to_string()} }}results in the same behavior.

      The document even receives the same ObjectId when the key is different each time.

      Cargo.toml
      mongodb = "2.0.0-beta.2"
      serde = "1.0.126"
      tokio =

      { version = "1.8.1", features = ["macros", "net", "rt-multi-thread", "sync", "fs", "time"] }

      MongoDB Version: 4.4
      Operating System: Ubuntu 20.04

            Assignee:
            patrick.freed@mongodb.com Patrick Freed
            Reporter:
            piotr.morawski@syncflux.io Piotr Morawski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: