Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code review fixes
  • Loading branch information
sssilver committed Nov 29, 2016
1 parent b516f7e commit 35c3d19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions #test#
@@ -0,0 +1,2 @@
rocket in the sky, don't ask me why

15 changes: 10 additions & 5 deletions README.md
Expand Up @@ -16,9 +16,14 @@ This crate works with Cargo and can be found on

```toml
[dependencies]
bson = "*"
bson = "0.3.2"
```
## Usage
Link the library in _main.rs_:
```rust
#[macro_use(bson, doc)]
extern crate bson;
```

Prepare your struct for Serde serialization:
```rust
Expand All @@ -42,19 +47,19 @@ let person = Person {
};

let serialized_person = bson::to_bson(&person)?; // Serialize
if let bson::Bson::Document(document) = serialized {

if let bson::Bson::Document(document) = serialized_person {
mongoCollection.insert_one(document, None)?; // Insert into a MongoDB collection
} else {
println!("Error converting the BSON object into a MongoDB document")
println!("Error converting the BSON object into a MongoDB document");
}
```

Deserialize the struct:
```rust
// Read the document from a MongoDB collection
let person_document = mongoCollection.find_one(Some(doc! { "_id" => "12345" }), None)?
.expect("Document not found")
.expect("Document not found");

// Deserialize the document into a Person instance
let person = bson::from_bson(bson::Bson::Document(person_document))?
Expand Down

0 comments on commit 35c3d19

Please sign in to comment.