convert_collection_to_jsonb

Function convert_collection_to_jsonb 

Source
pub async fn convert_collection_to_jsonb(
    database: &Database,
    collection_name: &str,
) -> Result<Vec<(String, Value)>>
Expand description

Convert an entire MongoDB collection to JSONB format

Reads all documents from a collection and converts them to JSONB. Returns a vector of (id, json_data) tuples ready for insertion.

§ID Generation Strategy

  • Uses MongoDB’s _id field as the ID (converted to string)
  • ObjectId is converted to hex string
  • Other ID types are converted to string representation

§Arguments

  • database - MongoDB database reference
  • collection_name - Collection name (must be validated)

§Returns

Vector of (id_string, json_data) tuples for batch insert

§Security

Collection name should be validated before calling this function.

§Examples

let client = connect_mongodb("mongodb://localhost:27017/mydb").await?;
let db = client.database("mydb");
let collection = "users";
validate_table_name(collection)?;
let rows = convert_collection_to_jsonb(&db, collection).await?;
println!("Converted {} documents to JSONB", rows.len());