Skip to content

Commit b323a2f

Browse files
kperzonyitoo
authored andcommitted
Edit example in README.md (#97)
* Edit example in README.md Querying a document with a string id doesn't work. Instead, you must wrap it in an ObjectId! * Edit example in README.md Change field and fix error in example
1 parent bf3c702 commit b323a2f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Prepare your struct for Serde serialization:
3333
#[derive(Serialize, Deserialize, Debug)]
3434
pub struct Person {
3535
#[serde(rename = "_id")] // Use MongoDB's special primary key field name when serializing
36-
pub id: String,
36+
pub id: bson::oid::ObjectId,
3737
pub name: String,
3838
pub age: i32
3939
}
@@ -63,7 +63,7 @@ Deserialize the struct:
6363

6464
```rust
6565
// Read the document from a MongoDB collection
66-
let person_document = mongoCollection.find_one(Some(doc! { "_id": "12345" }), None)?
66+
let person_document = mongoCollection.find_one(Some(doc! { "_id": bson::oid::ObjectId::with_string("12345").expect("Id not valid") }), None)?
6767
.expect("Document not found");
6868

6969
// Deserialize the document into a Person instance

0 commit comments

Comments
 (0)