Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 755 Bytes

README.md

File metadata and controls

32 lines (22 loc) · 755 Bytes

mongodb-macro

MongoDB Macro is a crate with macros for quickly creating structures to work with mongodb

Examples

use mongodb::{Client, bson::Bson};
use mongodb_macro::Parser;

mongodb_macro::config!(Opts);
//equal
//mongodb_macro::config!(Opts; "DB_NAME", "COLLECTION_NAME","DB_URL");

//or
//mongodb_macro::config!(Opts, "MONGO");
//equal
//mongodb_macro::config!(Opts; "MONGO_DB_NAME", "MONGO_COLLECTION_NAME","MONGO_DB_URL");

async fn main() -> std::io::Result<()> {

    let opts = Opts::parse();

    let client = mongodb::Client::with_uri_str(opts.db_url).await.expect("failed to connect");
    let db = client.database(&opts.db_name);
    let collection = db.collection::<Bson>(&opts.collection_name);

    ...
}

License: MIT