#polars #dataframe #query-engine #arrow

polars-mongo

Connector to read polars dataframes from mongodb collections

2 unstable releases

0.2.0 Sep 19, 2022
0.1.0 Aug 21, 2022

#40 in #query-engine

26 downloads per month

MIT license

24KB
505 lines

polars-mongo

This package extends polars to read from mongodb collections via the LazyFrame apis.


lib.rs:

Polars mongo is a connector to read from a mongodb collection into a Polars dataframe. Usage:

use polars::prelude::*;
use polars_mongo::prelude::*;

pub fn main() -> PolarsResult<()> {
    let connection_str = std::env::var("POLARS_MONGO_CONNECTION_URI").unwrap();
    let db = std::env::var("POLARS_MONGO_DB").unwrap();
    let collection = std::env::var("POLARS_MONGO_COLLECTION").unwrap();

    let df = LazyFrame::scan_mongo_collection(MongoScanOptions {
        batch_size: None,
        connection_str,
        db,
        collection,
        infer_schema_length: Some(1000),
        n_rows: None,
    })?
    .collect()?;

    dbg!(df);
    Ok(())
}

Dependencies

~58MB
~1M SLoC