Coder Social home page Coder Social logo

zumero / zmongo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mongodb-labs/mongo-rust-driver-prototype

0.0 7.0 0.0 3.95 MB

Home Page: http://mongodbinc-interns.github.io/mongo-rust-driver-prototype/

License: Apache License 2.0

Rust 100.00%

zmongo's Introduction

Travis Crates.io License

MongoDB Rust Driver Prototype

This branch contains active development on a new driver written for Rust 1.0.

The API and implementation are currently subject to change at any time. You must not use this driver in production as it is still under development and is in no way supported by MongoDB Inc. We absolutely encourage you to experiment with it and provide us feedback on the API, design, and implementation. Bug reports and suggestions for improvements are welcomed, as are pull requests.

Installation

Dependencies

Importing

The 1.0 driver is available on crates.io. To use the MongoDB driver in your code, add the bson and mongodb packages to your Cargo.toml:

[dependencies]
bson = "0.1.3"
mongodb = "0.1.0"

Then, import the bson and driver libraries within your code.

#[macro_use(bson, doc)]
extern crate bson;
extern crate mongodb;

Examples

Here's a basic example of driver usage:

use bson::Bson;
use mongodb::{Client, ThreadedClient};
use mongodb::db::ThreadedDatabase;

fn main() {
    let client = Client::connect("localhost", 27017)
        .ok().expect("Failed to initialize standalone client.");

    let coll = client.db("test").collection("movies");

    let doc = doc! { "title" => "Jaws",
                      "array" => [ 1, 2, 3 ] };

    // Insert document into 'test.movies' collection
    coll.insert_one(doc.clone(), None)
        .ok().expect("Failed to insert document.");

    // Find the document and receive a cursor
    let mut cursor = coll.find(Some(doc.clone()), None)
        .ok().expect("Failed to execute find.");

    let item = cursor.next();

    // cursor.next() returns an Option<Result<Document>>
    match item {
        Some(Ok(doc)) => match doc.get("title") {
            Some(&Bson::String(ref title)) => println!("{}", title),
            _ => panic!("Expected title to be a string!"),
        },
        Some(Err(_)) => panic!("Failed to get next from server!"),
        None => panic!("Server returned no results!"),
    }
}

Documentation

Documentation is built using Cargo. The latest documentation can be found here. Generated documentation using cargo doc can be found under the target/doc/ folder.

zmongo's People

Contributors

saghm avatar kyeah avatar vkarpov15 avatar alabid avatar ayosec avatar therustmonk avatar

Watchers

Troy Stanger avatar Paul Roub avatar James Cloos avatar Eric Sink avatar  avatar Zumero avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.