-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
-
Environment:MongoDB server version: 4.2.3 (using Docker)
Hello
I apologize if my English is strange.
I tried below code.
Cargo.toml
[dependencies] mongodb = "0.9.1" bson = "0.14.0" uuid = { version = "0.8.1", features = ["v4"]}
src/main.rs
#[macro_use] extern crate bson; use bson::Bson; use bson::spec::BinarySubtype; use mongodb::Client; use uuid::Uuid; fn main() { let client = Client::with_uri_str("mongodb://localhost:27017").unwrap(); let collection = client.database("mydb").collection("test"); let id = Bson::Binary(BinarySubtype::UuidOld, Uuid::new_v4().as_bytes().to_vec()); collection.insert_one(doc! {"id": id, "name": "aaa"}, None).unwrap(); for doc in collection.find(None, None).unwrap() { match doc { Ok(doc) => { println!("{}", doc); } Err(e) => { eprintln!("{}", e); } } } }
Output:
{ _id: ObjectId("5e62c72d0092514100eaa03e"), id: BinData(0, 0xb28894c6bc334de99a9c0968dc1fefda), name: "aaa" }
Even though BinarySubtype should have been restored as 3 (UuidOld), it was 0 (Generic).
DB:
> use mydb switched to db mydb > db.test.find({}).pretty() { "_id" : ObjectId("5e62c72d0092514100eaa03e"), "id" : BinData(3,"soiUxrwzTemanAlo3B/v2g=="), "name" : "aaa" }
It seems to be stored in the database.
Is this code has something mistaken?