document_to_json

Function document_to_json 

Source
pub fn document_to_json(document: &Document) -> Result<Value>
Expand description

Convert a MongoDB document to JSON object

Converts all fields in the document to JSON, preserving all types.

§Arguments

  • document - BSON document from MongoDB

§Returns

JSON object ready for JSONB storage

§Examples

let doc = doc! {
    "name": "Alice",
    "age": 30,
    "active": true
};
let json = document_to_json(&doc).unwrap();
assert_eq!(json["name"], "Alice");
assert_eq!(json["age"], 30);