# Mongoc and DataFrames

**URL:** <https://discourse.julialang.org/t/mongoc-and-dataframes/104622>\
**Category:** General Usage\
**Tags:** question, dataframes\
**Created:** [October 5, 2023, 5:48pm UTC](https://discourse.julialang.org/t/mongoc-and-dataframes/104622 "2023-10-05T17:48:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ginger\_snaps](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ginger_snaps/32/203688_2.png) [@ginger\_snaps](https://discourse.julialang.org/u/ginger_snaps)\
**Post date:** [October 5, 2023, 5:48pm UTC](https://discourse.julialang.org/t/mongoc-and-dataframes/104622/1 "2023-10-05T17:48:24Z")

</div>

Hello, I work with mongo and financial data and I need to

1. read data from csv
2. write it to mongo
3. get from mongo DataFrame
4. dataframe as I just read it from csv file (types, etc)

I wrote some function for that

```julia
using Mongoc
using Distributed
using Logging
using JSONTables
using DataFrames

addprocs(5)
@everywhere using Mongoc

function set_from_csv_to_mongo(collection::Mongoc.Collection, path_to_file::String, return_df::Bool=true)
    df = CSV.read(path_to_file, DataFrame)
    jsonstr = objecttable(df);
    df_bson = Mongoc.BSON(jsonstr);
    append!(collection, [df_bson])
    println("Add $path_to_file to $collection")
    if return_df
        return df
    end
end

function get_data_from_mongo(collection::Mongoc.Collection, query::String="")
    mongo_data = Mongoc.find(storage.user_data);
    df = DataFrame(collect(mongo_data))
    return df
end

```

Then I try to put one \*.csv with simple structure Date, SharePrice1,SharePrice2,…  
I received the normal data frame from the first function (obviously I just read it from CSV), I saw this data in the collection, but I could not grab it back. I just received 1 row with no columns but arrays of prices and types just crashed to Any.

Does anyone know what are the best modules to work with MongoDB and DataFrames? How can I put it and get it normally? THX
