mongo-leaf

Crates.iomongo-leaf
lib.rsmongo-leaf
version0.1.3
sourcesrc
created_at2020-03-30 09:37:23.966579
updated_at2020-03-31 11:06:38.294882
descriptionSimple wrapper around the mongoc lib
homepage
repositoryhttps://github.com/cajun/mongo-leaf
max_upload_size
id224319
size129,699
Zac Kleinpeter (cajun)

documentation

README

Mongo Leaf

Example:

#[macro_use]
extern crate bson;
use mongo_leaf::prelude::*;
use std::env;

fn main() -> Result<()> {
  env::set_var("MONGODB_URI","mongodb://standard");
  let builder = Builder::new();
  let pool = builder.connect()?;
  let mut client = pool.pop();

  let db = client.default_database();
  let collection = db.get_collection("test");
  let doc = doc!{"name": "omg"};
  collection.insert_one(doc)?;

  let doc = doc!{"name": "foo"};
  collection.insert_one(doc)?;

  let count = collection.count(None)?;
  assert_eq!(2, count);

  let maybe: Result<Vec<bson::Document>> = collection.find(doc!{"name": "foo"}).collect();

  assert!(maybe.is_ok());
  let records = maybe.unwrap();

  assert_eq!(1, records.len());

  db.destroy(); // Drops the database
  Ok(())
}

Testing Instructions

cargo make up # NOTE: This runs docker-compose up -d
cargo make logs # This runs multi tail on the logs files
cargo make down # NOTE: This runs docker-compose down

docker-compose logs -f lib # This will run for a single service
Commit count: 60

cargo fmt