pub fn import_table(json: String, table_name: String, config: Config) -> () {
    let database = get_connection(config);
    let collection = database.collection(&table_name);

    // delete all documents in given collection
    collection
        .delete_many(doc! {}, None)
        .expect("Could not delete documents of collection!");

    let json_vec: Vec<Map<String, Value>> =
        serde_json::from_str(&json).expect("Could not parse json file!");

    let mut documents: Vec<Document> = vec![];

    for j in json_vec {
        let document: Document = Document::try_from(j).expect("Could not convert map to document!");
        documents.push(document);
    }

    collection
        .insert_many(documents, None)
        .expect("Error while inserting multiple collections!");
}
// Import collection given as json string
Import collection given as json string
Import collection given as json string
pub fn import_table(json: String, table_name: String, config: Config) -> () {
    let database = get_connection(config);
    let collection = database.collection(&table_name);
    // delete all documents in given collection
    collection
        .delete_many(doc! {}, None)
        .expect("Could not delete documents of collection!");
    let json_vec: Vec<Map<String, Value>> =
        serde_json::from_str(&json).expect("Could not parse json file!");
    let mut documents: Vec<Document> = vec![];
    for j in json_vec {
        let document: Document = Document::try_from(j).expect("Could not convert map to document!");
        documents.push(document);
    }
    collection
        .insert_many(documents, None)
        .expect("Error while inserting multiple collections!");
}
pub fn import_table ( json : String , table_name : String , config : Config ) -> ( ) { let database = get_connection ( config ) ; let collection = database . collection ( & table_name ) ; // delete all documents in given collection collection . delete_many ( doc ! { } , None ) . expect ( " " ) ; let json_vec : Vec < Map < String , Value > > = serde_json :: from_str ( & json ) . expect ( " " ) ; let mut documents : Vec < Document > = vec ! [ ] ; for j in json_vec { let document : Document = Document :: try_from ( j ) . expect ( " " ) ; documents . push ( document ) ; } collection . insert_many ( documents , None ) . expect ( " " ) ; }
Import collection given as json string
Import collection given as json string
json
String
table_name
String
config
Config
json
String
table_name
String
config
Config