Skip to content

Instantly share code, notes, and snippets.

@saghm
Created December 22, 2016 00:44
Show Gist options
  • Save saghm/c90d9178975a77caa8b6eeb0f7955a29 to your computer and use it in GitHub Desktop.
Save saghm/c90d9178975a77caa8b6eeb0f7955a29 to your computer and use it in GitHub Desktop.
extern crate mongodb;
#[macro_use] extern crate bson;
use mongodb::{Client, ClientOptions, ThreadedClient};
use mongodb::db::ThreadedDatabase;
fn main(){
let options = ClientOptions::with_log_file("/tmp/mongo-commands");
let client = Client::connect_with_options("domain.name", 27017, options).expect("Couldn't connect to mongodb database");
let database = client.db("db");
database.auth("user", "password").expect("Can't authenticate to database");
let collection = database.collection("collection");
let doc = doc! { "test" => "test" };
collection.insert_one(doc, None).expect("Couldn't insert a document");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment