All Projects → mongodb-labs → Mongo Rust Driver Prototype

mongodb-labs / Mongo Rust Driver Prototype

Licence: apache-2.0
This is superseded by the official MongoDB Rust Driver

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Mongo Rust Driver Prototype

Lua Mongo
MongoDB Driver for Lua
Stars: ✭ 81 (-79.23%)
Mutual labels:  mongodb-driver
Mongodb Plugin
MongoDB Plugin for Java
Stars: ✭ 236 (-39.49%)
Mutual labels:  mongodb-driver
java-spring-boot-mongodb-starter
MongoDB Blog Post: REST APIs with Java, Spring Boot and MongoDB
Stars: ✭ 57 (-85.38%)
Mutual labels:  mongodb-driver
Mongo.migration
On-the-fly migrations with MongoDB C# Driver
Stars: ✭ 99 (-74.62%)
Mutual labels:  mongodb-driver
Mongo Perl Driver
Perl driver for the MongoDB
Stars: ✭ 203 (-47.95%)
Mutual labels:  mongodb-driver
mango
Use mongo-go-driver like mgo
Stars: ✭ 37 (-90.51%)
Mutual labels:  mongodb-driver
Egg Mongo Native
MongoDB egg.js plugin using native driver.
Stars: ✭ 69 (-82.31%)
Mutual labels:  mongodb-driver
mongorover
Intern project - MongoDB driver for the Lua programming language - This Repository is NOT a supported MongoDB product
Stars: ✭ 52 (-86.67%)
Mutual labels:  mongodb-driver
Mongodb.entities
A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
Stars: ✭ 204 (-47.69%)
Mutual labels:  mongodb-driver
online-training
Online Training website using ASP.Net Core 2.0 & Angular 4
Stars: ✭ 26 (-93.33%)
Mutual labels:  mongodb-driver
Mongo Php Library
MongoDB PHP library
Stars: ✭ 1,391 (+256.67%)
Mutual labels:  mongodb-driver
Java Specialagent
Automatic instrumentation for 3rd-party libraries in Java applications with OpenTracing.
Stars: ✭ 156 (-60%)
Mutual labels:  mongodb-driver
ArchitectNow.ApiStarter
Sample ASP.NET Core 2 API Setup used by ArchitectNow for corresponding workshop presentations
Stars: ✭ 35 (-91.03%)
Mutual labels:  mongodb-driver
Erlmongo
Erlang driver for MongoDB with gridfs that works with maps and proplists
Stars: ✭ 90 (-76.92%)
Mutual labels:  mongodb-driver
laravel-logger
📝 Laravel 日志的扩展,更规范,更快速,更有效。
Stars: ✭ 21 (-94.62%)
Mutual labels:  mongodb-driver
Avocado
Strongly-typed MongoDB driver for Rust
Stars: ✭ 70 (-82.05%)
Mutual labels:  mongodb-driver
Mongo Swift Driver
The official MongoDB driver for Swift
Stars: ✭ 242 (-37.95%)
Mutual labels:  mongodb-driver
TMongoWire
Delphi MongoDB driver
Stars: ✭ 91 (-76.67%)
Mutual labels:  mongodb-driver
wily
Build Node.js APIs from the command line (Dead Project 😵)
Stars: ✭ 14 (-96.41%)
Mutual labels:  mongodb-driver
MongoDBLink
MongoDB driver for Mathematica
Stars: ✭ 18 (-95.38%)
Mutual labels:  mongodb-driver

This Repository is NOT a supported MongoDB product

Travis Crates.io docs.rs License

MongoDB Rust Driver Prototype

NOTE: This driver is superseded by the official MongoDB Rust driver, and will no longer be updated.

This branch contains active development on a new driver written for Rust 1.x and MongoDB 3.0.x.

The API and implementation are currently subject to change at any time. You should 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.

Note: This driver currently only supports MongoDB 3.0.x and 3.2.x. This driver is not expected to work with MongoDB 2.6 or any earlier versions. Do not use this driver if you need support for other versions of MongoDB.

Installation

Dependencies

Importing

The 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]
mongodb = "0.3.11"

Alternately, you can use the MongoDB driver with SSL support. To do this, you must have OpenSSL installed on your system. Then, enable the ssl feature for MongoDB in your Cargo.toml:

[dependencies]
# ...
mongodb = { version = "0.3.11", features = ["ssl"] }

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

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

or with Rust 2018:

extern crate mongodb;
use mongodb::{bson, doc};

Examples

Here's a basic example of driver usage:

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

fn main() {
    let client = Client::connect("localhost", 27017)
        .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!"),
    }
}

To connect with SSL, use either ClientOptions::with_ssl or ClientOptions::with_unauthenticated_ssl and then Client::connect_with_options. Afterwards, the client can be used as above (note that the server will have to be configured to accept SSL connections and that you'll have to generate your own keys and certificates):

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

fn main() {
    // Path to file containing trusted server certificates.
    let ca_file = "path/to/ca.crt";
    // Path to file containing client certificate.
    let certificate = "path/to/client.crt";
    // Path to file containing the client private key.
    let key_file = "path/to/client.key";
    // Whether or not to verify that the server certificate is valid. Unless you're just testing out something locally, this should ALWAYS be true.
    let verify_peer = true;

    let options = ClientOptions::with_ssl(ca_file, certificate, key_file, verify_peer);

    let client = Client::connect_with_options("localhost", 27017, options)
        .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.");

    ...
}

Testing

The driver test suite is largely composed of integration tests and behavioral unit-tests, relying on the official MongoDB specifications repo.

The easiest way to thoroughly test the driver is to set your fork up with TravisCI. However, if you'd rather test the driver locally, you'll need to setup integration and specification tests.

NOTE: Each integration test uses a unique database/collection to allow tests to be parallelized, and will drop their dependencies before running. However, effects are not cleaned up afterwards.

Setting up integration tests

All integration tests run on the default MongoDB port, 27017. Before running the tests, ensure that a test database is setup to listen on that port.

If you don't have mongodb installed, download and install a version from the MongoDB Download Center. You can see a full list of versions being tested on Travis in the travis config.

After installation, run a MongoDB server on 27017:

mkdir -p ./data/test_db
mongod --dbpath ./data/test_db

Setting up the specifications submodule

Pull in the specifications submodule at tests/json/data/specs.

git submodule update --init

Running Tests

Run tests like a regular Rust program:

cargo test --verbose
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].