This Repository is NOT a supported MongoDB product
MongoDB Rust Driver Prototype - Can't Wait Any Longer
This fork contains quick fixes for the mongodb-labs's mongo rust driver prototype. This isn't active development. The goal is only to quickly fix issues with the current driver until the new official driver is released. Pull requests are welcomed.
Version 0.4 is fully compatible with the original driver. Other versions might break compatibility.
Note: This driver 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
:
[]
= { = "mongodb_cwal", = "0.4" }
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:
[]
= { = "mongodb_cwal", = "0.4", = ["ssl"] }
Then, import the bson and driver libraries within your code.
extern crate mongodb;
or with Rust 2018:
use ;
Examples
Here's a basic example of driver usage:
use ;
use ;
use ThreadedDatabase;
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 ;
use ;
use ThreadedDatabase;
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